Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

__call() not being called!

Status
Not open for further replies.

MasterKaos

Programmer
Jan 17, 2004
107
GB
Am i doing something wrong here, or is this a PHP bug?

Code:
<?php

class Foo{	
	public function __call($name, $arguments){	
		return 'foo';
	}	
}

class Foo_Bar extends Foo {	
	public function getFoo(){
		return parent::getFoo(); //line 11
	}	
}

$foo = new Foo();
$foobar = new Foo_Bar();

echo $foo->getFoo();
echo $foobar->getFoo();

/**
 * output:
 * foo
 * Fatal error: Call to undefined method Foo::getfoo() in /home/public_html/FooBar.php on line 11
 */

?>

What strikes me as particularly odd, is that the PHP error refers to the method in lowercase rather than camelCase....

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
running version 5.2.1.

Don't you think if i was running < 5 i'd get syntax errors for 'public', etc?

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
Don't you think if i was running < 5 i'd get syntax errors for 'public', etc?
That's a good question. I do not know. But I don't think that would necessarily be true, at least for recent 4.x versions.


It may just be that the "parent::" scope-resolution operator requires an exact function name to call.



Want the best answers? Ask the best questions! TANSTAAFL!
 
I think the behaviour is consistent with the wording of the php manual

Both method calls and member accesses can be overloaded via the __call, __get and __set methods. These methods will only be triggered when your object or inherited object doesn't contain the member or method you're trying to access.

you are trying to trigger an overloading of an ancestor object from an inherited object, which is not within the use case described above.

i am likewise surprised that a call in studly caps is not reflected in php's error message. it would be in reflected in procedural code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top