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? Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.