php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40621 Crash when constructor called inappropriately (statically)
Submitted: 2007-02-24 20:57 UTC Modified: 2007-02-24 21:31 UTC
From: sean@php.net Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID:
 [2007-02-24 20:57 UTC] sean@php.net
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-24 21:31 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC