note 52517 deleted from language.oop5.autoload by cmb
| From: | cmb@php.net | Date: | Sun, 26 May 2019 09:04:55 +0000 |
| Subject: | note 52517 deleted from language.oop5.autoload by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211124@lists.php.net to get a copy of this message | ||
Note Submitter: scott at webscott dot com
----
__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.