From:             yml at yml dot com
Operating system: Linux (redhat 9)
PHP version:      5.0.3
PHP Bug Type:     Scripting Engine problem
Bug description:  object reference being dropped. $this getting lost.

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 [EMAIL PROTECTED]
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

-- 
Edit bug report at http://bugs.php.net/?id=31525&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31525&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31525&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31525&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31525&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31525&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31525&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31525&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31525&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31525&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31525&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31525&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31525&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31525&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31525&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31525&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31525&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31525&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31525&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31525&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31525&r=mysqlcfg

Reply via email to