faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 10 people (80%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

Do member functions within a class incur any memory penalty when an object of that class is instantiated.

Feb 18th, 2008 19:34
dman, David Marley, Paul Kenneth Egell-Johnsen, http://www.ttnr.org


I just found the information:
http://www.zend.com/zend/art/ref-count.php
(search for objects, it should be a section in there 2/3 down the page):
"Some of the advantages of PHP 4 reference counting are less significant
with objects, since objects always have their own copy made on a method
(function) call. However, the object's properties do use reference
counting. See also Function parameters and reference counting."
There is the answer. The unprecedented approach...
In the light of this information, I think I would be reluctant to use 
PHP objects as anything more than data structures unless the 
application was very trivial.
This seems to be the advice of the PHP community in general but it 
would be helpful if the PHP developers themselves were more direct 
about the caveats of using objects. I wonder how many application 
developers are using classes extensively in their code without being 
aware of the potential drawbacks.