php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30112 Crash when __ToString() called from object with undefined property
Submitted: 2004-09-16 13:39 UTC Modified: 2004-11-04 21:51 UTC
From: jw at jwscripts dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 5.0.2 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jw at jwscripts dot com
New email:
PHP Version: OS:

 

 [2004-09-16 13:39 UTC] jw at jwscripts dot com
Description:
------------
When the __toString() method is called from a returned object to return an undefined property, Apache 2.0.48 crashes.



Reproduce code:
---------------
<?

class Foo {
	public function doSomething() {
		return new Foo;
	}

	public function __toString () {
		return $this->undefined;
	}
}

$foo = new Foo;
print $foo->doSomething();

?>

Expected result:
----------------
Notice:  Undefined property:  Foo::$undefined
Fatal error:  Method Foo::__toString() must return a string value

Actual result:
--------------
Apache Crash:
=============
szAppName : Apache.exe  szAppVer : 2.0.48.0     
szModName : php5ts.dll     
szModVer  : 5.0.1.1     offset   : 0004dd7f

+ the above messages 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-25 13:33 UTC] jw at jwscripts dot com
Bug persists in version 5.0.2, the notice and fatal error are not displayed (crash is more severe).
 [2004-09-25 14:40 UTC] johannes@php.net
#0  0x08136dc9 in zend_get_class_entry (zobject=0x81f735c) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend_API.c:204 
#1  0x0814d413 in zend_std_cast_object_tostring 
(readobj=0x81f735c, 
    writeobj=0xbfffca40, type=3, should_free=0) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend_object_handlers.c:938 
#2  0x0815bd96 in zend_echo_handler 
(execute_data=0xbfffcbb0, 
    opline=0x81f57a0, op_array=0x81f124c) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend_execute.c:1984 
#3  0x0815be3c in zend_print_handler 
(execute_data=0xbfffcbb0, 
    opline=0x81f57a0, op_array=0x81f124c) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend_execute.c:2002 
#4  0x0815ab28 in execute (op_array=0x81f124c) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend_execute.c:1400 
#5  0x081365bf in zend_execute_scripts (type=8, 
retval=0x0, file_count=3) 
    at /home/johannes/src/php/php-5.0.2/Zend/zend.c:1060 
#6  0x080f0edc in php_execute_script 
(primary_file=0xbfffeff0) 
    at /home/johannes/src/php/php-5.0.2/main/main.c:1629 
#7  0x0816775a in main (argc=1, argv=0xbffff094) 
    at /home/johannes/src/php/php-5.0.2/sapi/cli/php_cli.c:943 
 
 [2004-09-27 14:08 UTC] ante dot dfg at moj dot net
I can confirm this on Win XP sp1 using Apache 1.3.31 and php 5.0.2

szAppName : Apache.exe     szAppVer : 0.0.0.0     szModName : php5ts.dll     
szModVer : 5.0.2.2     offset : 0004e27f
 [2004-11-04 13:54 UTC] thekid@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Now prints out:

Fatal error: Method Foo::__toString() must return a string value in /usr/home/thekid/test.php on line 14
 [2004-11-04 21:51 UTC] jw at jwscripts dot com
Works as expected now, thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC