|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-01-13 00:49 UTC] yml at yml dot com
Description: ------------ PHP 5.0.3 using the recommended php.ini with all warnings and errors turned on. RedHat 9. Apache 1.3.33. Config: ./configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --prefix=/usr/local/php_5.0.3 --with-mcrypt=/usr/local/lib --with-gd --with-jpeg-dir=/usr/lib --with-zlib-dir=/usr/lib --with-png-dir=/usr/lib --enable-debug --enable-dmalloc --disable-inline-optimization This may be related to bug http://bugs.php.net/31508. Under PHP 4.3.10 the section of code in question causes a busy loop. Under PHP 5 it causes an object to be dropped. More info, sample code and a sample run can be found at: http://www.yml.com/homepage.html?COMP=clog_list&cmd=detail&cs_clog_entries_ref=149 I have a test case that is a radically reduced version of a large body of code. fv_baseComponent extends fv_baseWidget which extends fvTree. I create a minimal fv_baseComponent. It calls a method in the fv_baseWidget base class called getAttributeValue(). getAttributeValue calls getParentControl() which is present in both fv_baseWidget and fv_baseComponent. In fv_baseComponent getParentControl just returns "$this". The returned value is then used to call a method in the fv_baseComponent class. All this happens in the constructor for fv_baseComponent (which I suspect is the cause of the problem). Once the getAttributeValue() is called in the fv_baseComponent constructor, '$this' is no longer a valid object. If I turn on PHP 4 compatibility mode it seems to work. The code works under PHP 4. (however in the full application the same code seems to have problems under PHP 4.3.10 causing a busy loop). If you need to contact me from an email address other than bugs@php.net please use the form at http://www.yml.com/Contact_Yermo.html otherwise I will miss your email in all the spam I get. Reproduce code: --------------- See the download available at: http://www.yml.com/homepage.html?COMP=clog_list&cmd=detail&cs_clog_entries_ref=149 It contains base_widget.php, base_component.php, fvTree.php and test.php. The relevant snippet from test.php contains: $currentComponent =& new fv_baseComponent( $nullVar, $nullVar, $nullVar, "static", $nullVar ); ddt( "After creating fv_baseComponent - currentComponent type is '" . gettype( $currentComponent ) . "'"); $currentComponent->getAttributeValue( "hello" ); // at this point $this is destroyed. Is "unknown type". ddt( "after getAttributeValue() call - currentComponent type is '" . gettype( $currentComponent ) . "'" ); // this method call will fail. $currentComponent->setName( "test" ); ddt( "The end - currentComponent type is '" . gettype( $currentComponent ) . "'"); Expected result: ---------------- PHP should not produce any errors when the above is run. Actual result: -------------- test.php:30 - before class includes test.php:30 - Creating fv_staticCtrl instance test.php:30 - fv_baseComponent Constructor: Before getAttributeValue() call. Type of 'this' is 'object' test.php:30 - fv_basewidget::getAttributeValue() - Object id #1 is 'object' test.php:30 - fv_baseWidget::getAttributeValue() - value 'Hello from varLookupATTRS' - type of parentComponent object is 'object' test.php:30 - fv_baseComponent Constructor: after getAttributeValue() call. Type of 'this' is 'object' Warning: Attempt to assign property of non-object in /usr/local2/WWW/mobie.yml.com/mobie/admin_ui/tests/php_5_test/base_component.php on line 125 test.php:30 - After creating fv_baseComponent - currentComponent type is 'object' test.php:30 - fv_basewidget::getAttributeValue() - Object id #1 is 'object' test.php:30 - fv_baseWidget::getAttributeValue() - value 'Hello from varLookupATTRS' - type of parentComponent object is 'object' test.php:30 - after getAttributeValue() call - currentComponent type is 'unknown type' Fatal error: Call to a member function setName() on a non-object in /usr/local2/WWW/mobie.yml.com/mobie/admin_ui/tests/php_5_test/test.php on line 59 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 21:00:01 2025 UTC |
FWIW, here's a shorter script that reproduces the problem for me on PHP 5.0.3: <?php class Foo { function getThis() { return $this; } function destroyThis() { $baz =& $this->getThis(); } } $bar = new Foo(); $bar->destroyThis(); var_dump($bar); ?> This outputs: NULL If I change the assign-by-reference operator (=&) to the normal assignment operator (=) inside destroyThis(), I get: object(Foo)#1 (0) { } Hope this helps...True, if getThis() is declared to return a reference then everything works as expected. However, looking through the original reproduce code I noticed something else. If you add parentheses around $this in getThis() then the unexpected behavior returns. Complete code: <?php class Foo { function &getThis() { return ($this); } function destroyThis() { $baz =& $this->getThis(); } } $bar = new Foo(); $bar->destroyThis(); var_dump($bar); ?> Produces: NULL Expected: object(Foo)#1 (0) { }