#40621 [NEW]: Crash when constructor called inappropriately (statically)

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40621 [NEW]: Crash when constructor called inappropriately (statically)

    From: [email]sean@php.net[/email]
    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 [url]http://bugs.php.net/?id=40621&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40621&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40621&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40621&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40621&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40621&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40621&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40621&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40621&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40621&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40621&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40621&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40621&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40621&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40621&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40621&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40621&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40621&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40621&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40621&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40621&r=mysqlcfg[/url]
    sean@php.net Guest

  2. Similar Questions and Discussions

    1. #40398 [NEW]: parent and self callback functions erroneously called statically
      From: levi at alliancesoftware dot com dot au Operating system: PHP version: 5CVS-2007-02-08 (CVS) PHP Bug Type: Scripting...
    2. #39868 [NEW]: Destructor is called allthought constructor is never called
      From: jb at ez dot no Operating system: Kubuntu 6.10 PHP version: 5.2.0 PHP Bug Type: *General Issues Bug description: ...
    3. #39678 [Opn->Bgs]: __set and __get not called where a class attribute is called statically
      ID: 39678 Updated by: tony2001@php.net Reported By: denis at edistar dot com -Status: Open +Status: ...
    4. #39678 [NEW]: __set and __get not called where a class attribute is called statically
      From: denis at edistar dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem Bug...
    5. #24661 [Opn->Bgs]: xmlCleanupParser called multiple times and causes crash
      ID: 24661 Updated by: rrichards@php.net Reported By: wez@php.net -Status: Open +Status: Bogus Bug...
  3. #2

    Default #40621 [Opn->Csd]: Crash when constructor called inappropriately (statically)

    ID: 40621
    Updated by: [email]tony2001@php.net[/email]
    Reported By: [email]sean@php.net[/email]
    -Status: Open
    +Status: Closed
    Bug Type: Reproducible crash
    Operating System: Linux
    PHP Version: 5.2.1
    New Comment:

    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
    [url]http://snaps.php.net/[/url].

    Thank you for the report, and for helping us make PHP better.




    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-24 20:57:29] [email]sean@php.net[/email]

    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 this bug report at [url]http://bugs.php.net/?id=40621&edit=1[/url]
    tony2001@php.net Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139