mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
Fixed bug #44141 (private parent constructor callable through static function)
This commit is contained in:
parent
de7ee656f7
commit
9181650764
25
Zend/tests/bug44141.phpt
Normal file
25
Zend/tests/bug44141.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
Bug #44141 (private parent constructor callable through static function)
|
||||
--FILE--
|
||||
<?php
|
||||
class X
|
||||
{
|
||||
public $x;
|
||||
private function __construct($x)
|
||||
{
|
||||
$this->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
|
@ -1052,7 +1052,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 %v::%v() from context '%v'", constructor->common.scope->name, constructor->common.function_name, EG(scope)->name);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user