]> granicus.if.org Git - php/commitdiff
MFH: fix #40621 (Crash when constructor called inappropriately (statically))
authorAntony Dovgal <tony2001@php.net>
Sat, 24 Feb 2007 21:30:48 +0000 (21:30 +0000)
committerAntony Dovgal <tony2001@php.net>
Sat, 24 Feb 2007 21:30:48 +0000 (21:30 +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 a5e117daf06ac6596ff7017216abf7f60166ae09..0a4b0acc2e9431db7532f5078d0185c51aab0a5d 100644 (file)
@@ -1765,7 +1765,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
index c91c9f40832687c86634414da59c9f30696c3616..f3ff1b63319fe92cd0473bb3976e6130475568de 100644 (file)
@@ -694,7 +694,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -898,7 +898,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1059,7 +1059,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1219,7 +1219,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;
@@ -1312,7 +1312,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 %s::__construct()", ce->name);
                }
                EX(fbc) = ce->constructor;