Bug #71119 [Opn->Nab]: Cannot override methods on extended classes
Edit report at https://bugs.php.net/bug.php?id=71119&edit=1
ID: 71119
Updated by: requinix@php.net
Reported by: chazmead89 at gmail dot com
Summary: Cannot override methods on extended classes
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Mac OSX 10.8.5
PHP Version: 7.0.0
Block user comment: N
Private report: N
New Comment:
"Basic method overriding" is you making sure your child class conforms to the interface
specified by the parent class. That includes type hints.
Previous Comments:
------------------------------------------------------------------------
[2015-12-14 18:28:48] chazmead89 at gmail dot com
Description:
------------
PHP Warning: Declaration of B::foo(string $boo) should be compatible with A::foo(array $bar) in php
shell code on line 3
This should not be a warning... this is basic method overriding, and should be perfectly good code.
For some reason I get a fatal error on apache handler, but only warning on CLI, possibly Xdebug RC4
escalating it as a bug in XDdebug.
Test script:
---------------
class A {
public function foo(string $bar) { print_r($bar); }
}
class B extends A {
public function foo(array $bar) { print_r($bar); }
}
Actual result:
--------------
PHP Warning: Declaration of B::foo(string $boo) should be compatible with A::foo(array $bar) in php
shell code on line 3
Warning: Declaration of B::foo(string $boo) should be compatible with A::foo(array $bar) in php
shell code on line 3
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71119&edit=1
Thread (8 messages)