views:

90

answers:

2

I have a class Logger which, among other things has a method Log.
As Log is the most common use of the Logger instance, I have wired __invoke to call Log

Another class, "Site" contains a member "Log", an instance of Logger.

Why would this work:

$Log = $this->Log;  
$Log("Message");

But not this:

$this->Log("Message");

The former fails with "PHP Fatal error: Call to undefined method Site::Log()"
Is this a limitation of the callable object implementation, or am I misunderstanding something?

+1  A: 
Matthew Scharley
+1  A: 

Same reasons you can't do this:

$value = $this->getArray()["key"];

or even this

$value = getArray()["key"];

Because PHP syntax doesn't do short hand very well.

Kendall Hopkins
Mostly because of the loose typing. There's no way of actually infering what you might mean to do, so it defaults to erroring early.
Matthew Scharley
I've written an odd preparser which allows to write such expressions: http://code.google.com/p/php-preparser/ :) (can I "advertise" my open-source solutions here?)
valya