At 06:27 PM 6/29/2001 -0500, Dean Hall wrote:
>Okay, perhaps I need to spend some more time studying language
>compilers/interpreters, but I've got a question regarding object creation in
>the PHP core.
>
>Basically, what, internally, is part of a PHP object (class instantiation)?
>I know Zend started using reference counting a while back, so I guess all
>objects are basically references, but I need to know how much of the class
>information is contained in the objects themselves.
>
>So if I have a class like so:
>
>class foo {
>     var $var1;
>     var $var2;
>     var $var3;
>
>     function func1() { ... }
>     function func2() { ... }
>     function func3() { ... }
>}
>
>and instantiate it like so:
>
>$foo1 = new foo;
>
>will the internal representation of the $foo object contain definitions for
>all the variables and functions? So that when I make a second object:
>
>$foo2 = new foo;
>
>will its internal representation duplicate all those method definitions?
>
>My guess is that the most efficient implementation would be to have some
>sort of class template that holds, at the least, definitions for the
>methods, so that every instantiation refers to those method definitions in
>the static template instead of storing their own method definitions.
>Variables, since they can't be referenced statically in PHP, would have to
>be stored in the object itself; methods, however, could simply be
>implemented analogously to functions that take an object as their first
>method (i.e., like functions that operate on structs in C).

This is exactly how it works. The member variables are duplicated from a 
template and the method's are saved in the same template but are pointed to 
(i.e. not copied for each object).

Andi


>Any ideas? If you prefer, could you direct me to where in the source to look
>for an answer?
>
>The reason I'm worried about all this is that I'm writing a very large
>application, and I have to worry about object creation time and memory
>resources because I may have many distinct objects of the same type
>instantiated at the same time.
>
>Thanks.
>Dean.
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to