]> granicus.if.org Git - php/commitdiff
fix #40621 (Crash when constructor called inappropriately (statically))
authorAntony Dovgal <tony2001@php.net>
Sat, 24 Feb 2007 21:29:22 +0000 (21:29 +0000)
committerAntony Dovgal <tony2001@php.net>
Sat, 24 Feb 2007 21:29:22 +0000 (21:29 +0000)
Zend/tests/bug40621.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/bug40621.phpt b/Zend/tests/bug40621.phpt
new file mode 100644 (file)
index 0000000..564ba55
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #40621 (Crash when constructor called inappropriately (statically))
+--FILE--
+<?php
+
+class Foo {
+       private function __construct() { }
+       function get() {
+               self::__construct();
+       }
+}
+
+Foo::get();
+
+echo "Done\n";
+?>
+--EXPECTF--    
+Strict Standards: Non-static method Foo::get() should not be called statically in %s on line %d
+
+Fatal error: Non-static method Foo::__construct() cannot be called statically in %s on line %d
index 48ff1af5e637722f908292cb894f0749fed34ffd..d4cc862f6508c031e7bf413b7df9780d3b75410f 100644 (file)
@@ -1810,7 +1810,7 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV)
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
index 333571be7dd948ac25ef34bba743682a31289018..f01bf067d2fdc0b463236b06322c421493a4c4a4 100644 (file)
@@ -704,7 +704,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -925,7 +925,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1061,7 +1061,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1196,7 +1196,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1289,7 +1289,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
-               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+               if (EG(This) && Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
                        zend_error(E_COMPILE_ERROR, "Cannot call private %v::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;