summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Zend/tests/bug40621.phpt20
-rw-r--r--Zend/zend_vm_def.h2
-rw-r--r--Zend/zend_vm_execute.h10
3 files changed, 26 insertions, 6 deletions
diff --git a/Zend/tests/bug40621.phpt b/Zend/tests/bug40621.phpt
new file mode 100644
index 0000000000..564ba55be2
--- /dev/null
+++ b/Zend/tests/bug40621.phpt
@@ -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
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index a5e117daf0..0a4b0acc2e 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -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;
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index c91c9f4083..f3ff1b6331 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -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;