note 52517 added to language.oop5.autoload
| From: | scott at webscott dot com | Date: | Wed, 04 May 2005 12:40:51 +0000 |
| Subject: | note 52517 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88913@lists.php.net to get a copy of this message | ||
__autoload() seems to work when saving objects as session variables as well:
classLoader.php
<?php
function __autoload($className) {
require_once("$className.php");
}
?>
testClass.php
<?php
class testClass {
function __construct($propValue) {
$this->prop1 = $propValue;
}
function showProp() {
return $this->prop1;
}
}
?>
page1.php
<?php
require_once('classLoader.php');
session_start();
$_SESSION['testObj'] = new testClass('foo');
echo '<a href="page2.php">Go to page 2</a>';
?>
page2.php
<?php
require_once('classLoader.php');
session_start();
echo $_SESSION['testObj']->showProp(); // displays foo
?>
Works with multiple session objects as well. Tested on a Win2k/IIS machine.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52517
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52517&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52517&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52517&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52517&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52517&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52517&report=yes
Search -- http://master.php.net/manage/user-notes.php