|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-20 10:01 UTC] themastersleader at hotmail dot com
Description:
------------
When we implement an interface,
And we have a base class with a private function,
We can't use that name anymore for a public function in classes that extend the base class.
When we remove the implements everything works fine.
Reproduce code:
---------------
<?php
error_reporting( E_ALL );
set_error_handler('errorReporting');
interface test { }
class ParentClass
implements test
{
private function foo() { }
}
class ChildClass
extends ParentClass
{
public function foo(array $content) { }
}
function errorReporting($errno, $errstr, $errfile, $errline)
{
echo($errstr . '<br />');
}
?>
Expected result:
----------------
No error messages
Actual result:
--------------
Declaration of ChildClass::foo() should be compatible with that of ParentClass::foo()
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
this is not a bug extending a method means that in the sub-class the overrided method can be used as can i use it in the parent class so if i have function test($a, $b, $c){} in the subclasses every additional parameter must be "not required" to make the method working function test($a, $b, $c, $d=NULL, $e=NULL, $f=NULL) =NULL means that are not required so in your code class ChildClass extends ParentClass { public function foo(array $content=NULL) { } }a private method is exactly like the others... explained by the fact that a private method can be public in a subclass class A{private function x(){}} class B extends A{public function x(){parent::x()}}"a private method is exactly like the others... explained by the fact that a private method can be public in a subclass" Nooooo Here, try this: class A{private function x(){}} class B extends A{public function b(){x()}} as you can see, class b DID NOT inherited function x, it can call it from the parent class though, which is what you showed. Any way, see discussion here: http://stackoverflow.com/questions/3258523/is-this-a-php-bug-subclasses-must-declare-private-methods-with-the-same-signaturok i got it i'm sorry... a private method cannot obviously public in subclasses -__- so you are saying that any class can have ---their own method with same name with totally different signature---... because private methods does not depends by parent ones ok now i think that you are right fields works right... here is the proof: class A { private $test; public function __construct(){$this->test = "THIS IS A";} } class B extends A { private $test; public function printit(){echo isset($this->test) ?: '$this->test is not set';} } $b = new B(); $b->printit(); as you can see every class has its own field with the same name subclass-field does not inherits parent class's field