(Sammy Kaye Powers)
. Fixed bug #74269 (It's possible to override trait property with different
loosely-equal value). (pmmaga)
+ . Fixed bug #61970 (Restraining __construct() access level in subclass gives
+ a fatal error). (pmmaga)
- BCMath:
. Fixed bug #46564 (bcmod truncates fractionals). (liborm85)
--- /dev/null
+--TEST--
+Bug #61970 (Restraining __construct() access level in subclass gives a fatal error)
+--FILE--
+<?php
+
+class Foo {
+ public function __construct(){}
+}
+
+class Bar extends Foo {
+ protected function __construct(){}
+}
+
+echo 'DONE';
+--EXPECT--
+DONE
--- /dev/null
+--TEST--
+Bug #61970 (Restraining __construct() access level in subclass gives a fatal error - stays when implementing abstract)
+--FILE--
+<?php
+
+abstract class Foo {
+ abstract public function __construct();
+}
+
+class Bar extends Foo {
+ protected function __construct(){}
+}
+
+--EXPECTF--
+Fatal error: Access level to Bar::__construct() must be public (as in class Foo) in %s
--- /dev/null
+--TEST--
+Bug #61970 (Restraining __construct() access level in subclass gives a fatal error - stays when inheriting implemented abstract)
+--FILE--
+<?php
+
+abstract class Foo {
+ abstract public function __construct();
+}
+
+class Bar extends Foo {
+ public function __construct(){}
+}
+
+class Baz extends Bar {
+ protected function __construct(){}
+}
+
+--EXPECTF--
+Fatal error: Access level to Baz::__construct() must be public (as in class Bar) in %s
zend_error_noreturn(E_COMPILE_ERROR, "Cannot make non abstract method %s::%s() abstract in class %s", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name), ZEND_FN_SCOPE_NAME(child));
}
- /* Prevent derived classes from restricting access that was available in parent classes */
- if (UNEXPECTED((child_flags & ZEND_ACC_PPP_MASK) > (parent_flags & ZEND_ACC_PPP_MASK))) {
+ /* Prevent derived classes from restricting access that was available in parent classes (except deriving from non-abstract ctors) */
+ if (UNEXPECTED((!(child_flags & ZEND_ACC_CTOR) || (parent_flags & (ZEND_ACC_ABSTRACT | ZEND_ACC_IMPLEMENTED_ABSTRACT))) &&
+ (child_flags & ZEND_ACC_PPP_MASK) > (parent_flags & ZEND_ACC_PPP_MASK))) {
zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::%s() must be %s (as in class %s)%s", ZEND_FN_SCOPE_NAME(child), ZSTR_VAL(child->common.function_name), zend_visibility_string(parent_flags), ZEND_FN_SCOPE_NAME(parent), (parent_flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
}
echo "Done\n";
?>
--EXPECTF--
-Fatal error: Access level to DB::__construct() must be public (as in class mysqli) in %s%ebug38003.php on line %d
-
+Fatal error: Uncaught Error: Call to private DB::__construct() from invalid context in %s
+Stack trace:
+#0 {main}
+ thrown in %s