From 3e7e9d4af6c275618896dc971ec561d9f54d023e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 21 Feb 2008 13:55:45 +0000 Subject: [PATCH] Fixed bug #44141 (private parent constructor callable through static function) --- Zend/tests/bug44141.phpt | 25 +++++++++++++++++++++++++ Zend/zend_object_handlers.c | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug44141.phpt diff --git a/Zend/tests/bug44141.phpt b/Zend/tests/bug44141.phpt new file mode 100644 index 0000000000..1a9ee892b6 --- /dev/null +++ b/Zend/tests/bug44141.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #44141 (private parent constructor callable through static function) +--FILE-- +x = $x; + } +} + +class Y extends X +{ + static public function cheat($x) + { + return new Y($x); + } +} + +$y = Y::cheat(5); +echo $y->x, PHP_EOL; +--EXPECTF-- +Fatal error: Call to private X::__construct() from context 'Y' in %sbug44141.php on line 15 diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 3196e50a5d..449c32408b 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1025,7 +1025,7 @@ ZEND_API union _zend_function *zend_std_get_constructor(zval *object TSRMLS_DC) } else if (constructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { /* Ensure that if we're calling a private function, we're allowed to do so. */ - if (Z_OBJ_HANDLER_P(object, get_class_entry)(object TSRMLS_CC) != EG(scope)) { + if (constructor->common.scope != EG(scope)) { if (EG(scope)) { zend_error(E_ERROR, "Call to private %s::%s() from context '%s'", constructor->common.scope->name, constructor->common.function_name, EG(scope)->name); } else { -- 2.40.0