ID:               16591
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tthiery at yahoo dot de
-Status:           Open
+Status:           Closed
 Bug Type:         Feature/Change Request
 Operating System: Linux/Win2k/whatever
 PHP Version:      4.1.2
 New Comment:

__autoload() feature of PHP5 can be used for that. I tried the
following code and it works. __autoload() is called when the class name
is unkown. In this case the user is responsible for loading the class.

p.php
<?php

function __autoload($cname) {
        var_dump('class name'.$cname);
        require_once $cname.'.class.php';
}

function getInstance($cname) {
        require_once $cname.'.class.php';
        return new $cname();
}
if (!is_file('ser.dat')) {
        $a = getInstance("hello");
        file_put_contents('ser.dat', serialize($a));
} else {
        $a = unserialize(file_get_contents('ser.dat'));
}
var_dump($a);

?>
hello.class.php :
<?php

class hello {
        public $hello_var ="123";
        function hello() { printf("hello contstructor\n");
        }
}
?>



Previous Comments:
------------------------------------------------------------------------

[2002-04-13 14:09:42] tthiery at yahoo dot de

I define classes in extra scripts like this one: 

File: hello.class.php 
<? 
class Hello { 
function print() { 
echo "Hello"; 
} 
} 
?> 

I include and create them via a manufacturing function: 
$obj = myCreateObject("Hello"); 
myCreateObject lookup the file for Hello, include_once them, create the
object and returns it. 
But then the problem: I store the object to session and when I
unserialize the object in the next script, an error occurs. Clear, the
class script file isn't loaded. Until now I do the
serialize/unserialize via a trick (a register_shutdown_function store
all of these objects AND their meta data like classname in one session
var and in the next script all of them are unserialized manually). 

My Question: Is in the unserialize function and/or the session_decode
function a possibility of a callback function like myLoadClass("Hello")
for a serialized object (class Hello) ? 

And if the answer is a no: Hey PHP team it's an idea for a new
function. 

ps I post this message already in the zend.com forum PHP into future

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=16591&edit=1

Reply via email to