jed3 Posted October 23, 2006 Share Posted October 23, 2006 Hello,I would like to know how I might pass an Object between files?what I have is similar to this...[code]<?phpif($_GET['mode'] == 'send') { $email = $_GET['obj']; $email->sendMail();}$email = new EmailObject("to", "subject", "body");?><form action="email.php?mode=send&obj=<?php echo $email; ?>"><input type="submit" value="submit"></form>[/code]I am aware this is wrong, I just wanted to get my question across as straightforward as possible. I was trying to avoid having to use serialization, but if that would be the only method what would be the easiest way? Link to comment https://forums.phpfreaks.com/topic/24877-passing-objects-between-php-files/ Share on other sites More sharing options...
trq Posted October 23, 2006 Share Posted October 23, 2006 You need to serialize your object, and the easiest way is to use sessions. eg;obj.php[code=php:0]<?php class foo { private $bar function __construct($var) { $this->bar = $var; } function getBar() { return "this is ".$this->bar; } }?>[/code]p1.php[code=php:0]<?php session_start(); include 'obj.php'; $foo = new foo('a test'); $_SESSION['obj'] = $foo; echo "<a href='p2.php'>p2</a>";?>[/code]p2.php[code=php:0]<?php session_start(); include 'obj.php'; $foo = $_SESSION['obj']; echo $foo->getBar();?>[/code] Link to comment https://forums.phpfreaks.com/topic/24877-passing-objects-between-php-files/#findComment-113393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.