#40621 [NEW]: Crash when constructor called inappropriately (statically)
| From: | sean@php.net | Date: | Sat, 24 Feb 2007 20:57:29 +0000 |
| Subject: | #40621 [NEW]: Crash when constructor called inappropriately (statically) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-109476@lists.php.net to get a copy of this message | ||
From: sean@php.net
Operating system: Linux
PHP version: 5.2.1
PHP Bug Type: Reproducible crash
Bug description: Crash when constructor called inappropriately (statically)
Description:
------------
PHP 5.2.x (tried 5.2.1, 5.2.0) crashes if a constructor is called
statically from within the host class.
Code explains this better.
I realize I'm not SUPPOSED to do this, but I did it accidentally (I made a
mistake). I expect the error message. It shouldn't, however, crash.
Reproduce code:
---------------
php -r 'class Foo { private function __construct() { } function get() {
self::__construct(); } } Foo::get();'
Expected result:
----------------
E_FATAL
Here's 5.1.6:
Fatal error: Non-static method Foo::__construct() cannot be called
statically in Command line code on line 1
In 5.2.0, this was downgraded to E_STRICT, which I suspect is why it
crashes (E_FATAL would have bailed, E_STRICT tries to run this messed up
code).
Actual result:
--------------
here's the backtrace:
(gdb) run -r 'class Foo { private function __construct() { } function
get() { self::__construct(); } } Foo::get();'
Starting program: /usr/local/bin/php -r 'class Foo { private function
__construct() { } function get() { self::__construct(); } } Foo::get();'
[Thread debugging using libthread_db enabled]
[New Thread -1214503248 (LWP 28107)]
Strict Standards: Non-static method Foo::get() should not be called
statically in Command line code on line 1
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1214503248 (LWP 28107)]
0x083c425c in zend_get_class_entry (zobject=0x0)
at /home/sean/downloads/php-5.2.1/Zend/zend_API.c:248
248 if (Z_OBJ_HT_P(zobject)->get_class_entry) {
(gdb) bt
#0 0x083c425c in zend_get_class_entry (zobject=0x0)
at /home/sean/downloads/php-5.2.1/Zend/zend_API.c:248
#1 0x083ec877 in ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER (
execute_data=0xbfd5e800)
at /home/sean/downloads/php-5.2.1/Zend/zend_vm_execute.h:1222
#2 0x083e7fc3 in execute (op_array=0xb798f330)
at /home/sean/downloads/php-5.2.1/Zend/zend_vm_execute.h:92
#3 0x083e85ed in zend_do_fcall_common_helper_SPEC
(execute_data=0xbfd5e980)
at /home/sean/downloads/php-5.2.1/Zend/zend_vm_execute.h:234
#4 0x083e90c0 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER
(execute_data=0xbfd5e980)
at /home/sean/downloads/php-5.2.1/Zend/zend_vm_execute.h:322
#5 0x083e7fc3 in execute (op_array=0xb798d7fc)
at /home/sean/downloads/php-5.2.1/Zend/zend_vm_execute.h:92
#6 0x083b6e79 in zend_eval_string (
str=0xbfd5f911 "class Foo { private function __construct() { }
function get() { self::__construct(); } } Foo::get();", retval_ptr=0x0,
string_name=0x8522074 "Command line code")
at /home/sean/downloads/php-5.2.1/Zend/zend_execute_API.c:1151
#7 0x083b7012 in zend_eval_string_ex (
str=0xbfd5f911 "class Foo { private function __construct() { }
function get() { self::__construct(); } } Foo::get();", retval_ptr=0x0,
string_name=0x8522074 "Command line code", handle_exceptions=1)
at /home/sean/downloads/php-5.2.1/Zend/zend_execute_API.c:1185
#8 0x0843d555 in main (argc=3, argv=0xbfd5ed14)
at /home/sean/downloads/php-5.2.1/sapi/cli/php_cli.c:1153
--
Edit bug report at http://bugs.php.net/?id=40621&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40621&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40621&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40621&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40621&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40621&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40621&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40621&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40621&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40621&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40621&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40621&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40621&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40621&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40621&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40621&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40621&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40621&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40621&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40621&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40621&r=mysqlcfg