Edit report at https://bugs.php.net/bug.php?id=63247&edit=1
ID: 63247 User updated by: olivier at m2mobi dot com Reported by: olivier at m2mobi dot com Summary: Implemented abstract function with additional parameter having default value -Status: Closed +Status: Assigned Type: Bug -Package: Documentation problem +Package: Class/Object related Operating System: Windows/Linux PHP Version: 5.4.7 Assigned To: googleguy Block user comment: N Private report: N New Comment: Pacakge didi not match Previous Comments: ------------------------------------------------------------------------ [2012-10-09 14:28:28] google...@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. ------------------------------------------------------------------------ [2012-10-09 14:26:49] google...@php.net This is actually a documentation problem not a bug. The documentation states "Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same.", which means that any number of optional arguments are allowed in the child method's signature. This is what's happening here. The second argument is options so it doesn't actually conflict with the documented behavior. However, I too did not catch this at first glance. So I've expanded on the docs for abstract to elaborate on this a bit and added an example in the documentation demonstrating this feature. That should help clarify in the future :) ------------------------------------------------------------------------ [2012-10-09 13:52:25] olivier at m2mobi dot com Description: ------------ Implemented abstract function with additional parameter having default value doesn't cause any error. Will output: I am the first arg. I am the additional arg. I am the first arg. I am the additional arg default value. If no default value the script crash. Test script: --------------- <?php abstract class AbstractMother { public abstract function methodWithOneArg( $arg ); } class ConcreteChild extends AbstractMother { public function methodWithOneArg($arg, $arg2="I am the additional arg default value.") { echo $arg." ".$arg2 ; } } $child = new ConcreteChild() ; $child->methodWithOneArg( "I am the first arg.", "I am the additional arg.") ; echo "<br>" ; $child->methodWithOneArg("I am the first arg.") ; Expected result: ---------------- FATAL ERROR thrown Actual result: -------------- Just works, addition of a third argument is ignored: <?php class ConcreteChild2 extends AbstractMother { public function methodWithOneArg($arg, $arg2="I am the additional arg default value.", $arg3="I am another arg default value.") { echo $arg." ".$arg2." ".$arg3 ; } } echo "<br>" ;echo "<br>" ; $child2 = new ConcreteChild2() ; $child->methodWithOneArg( "I am the first arg.", "I am the additional arg.", "I am the other additional arg") ; echo "<br>" ; $child->methodWithOneArg( "I am the first arg.", "I am the additional arg.") ; echo "<br>" ; $child->methodWithOneArg("I am the first arg.") ; ?> Will output: I am the first arg. I am the additional arg. I am the first arg. I am the additional arg. I am the first arg. I am the additional arg default value. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63247&edit=1