Ok here is my problem I have a class A and a class B that extends class A. Both classes have a function called create. the create function from class A looks like this function create &create( $service, $component, $tariff) { } PHP: the create function from class B looks like this function create( $service, $component, $tariff, $date, $handle, $start) { } PHP: In my error_log I see this entry Any idea what the problem could be?
I can't replicate it with: <?php error_reporting(E_ALL); class A { function &create( $service, $component, $tariff) { echo 123; } } class B Extends A { function create( $service, $component, $tariff, $date, $handle, $start) { echo 456; } } $b = new B; $b->create('test', 'test2', 'test3', 'test4', 'test5', 'test6'); Code (markup): Would you be able to paste the code you're actually using? Either way, if you make your error_reporting PHP configuration setting less strict​, it should hide the error.
sorry can't really give any more details. But I think the problem is that one function has the & and the other doesn't. Any idea what that means?
I'm not quite sure you should have that & infront of "create". & is usually used when you pass a variable by reference, and I've never seen it used infront of a function name like that. The error you're getting is due to the fact that you're redeclearing the function "create" with other parameters in class B than the original method in class A. You need to use the exact same declaration in a subclass in PHP, and you cannot do actual method overloads like in java/C# etc (where you define multiple functions with different arguments).
From memory, prefixing a function name with an ampersand simply means it returns a reference to a variable, rather than a value.
That makes sense. The problem is still that the method declaration has to be equal to the one in class A
It shouldn't though - PHP shouldn't be that strict. I even tested on PHP 5.3.13 with the error reporting level set to E_ALL, and no error was raised. The child class should be able to override the parent class with a different set of parameters. It'd be interesting to see OPs php.ini file. Either way, it's more a warning, and it should be suppressed on a production environment.