I've been working with PHPTAL for quite some time, and have always been 
annoyed that from within the template an object's __get method was being 
ignored. I think I've tracked down the bug (in version 1.2.2, though it still 
present in trunk).

The scenario: an object, exampleObject, implements __isset, but returns false 
(exampleVariable is not set). exampleObject also implements __get, and returns 
something that isn't NULL.

As __isset is implemented, the if condition on line 378 is satisfied, but 
because exampleVariable is not set, the if condition on line 379 is not met, 
and the loop does not continue.

However, since the if condition on line 385 (checking to see if __get is 
implemented) is an elseif, it is skipped–the condition on line 378 passed–right 
to the if condition on line 394 (the one checking to see if __call is 
implemented). As exampleVariable isn't a method, it to fails, and the 
PHPTAL_Context:pathError method is executed.

My patch is simple, changing one line. Everything seems to work as expected 
with the change, though I'm happy to hear any problems you have with it.

diff --git a/PHPTAL/Context.php b/PHPTAL/Context.php
--- a/PHPTAL/Context.php
+++ b/PHPTAL/Context.php
@@ -382,7 +382,7 @@ class PHPTAL_Context
 // ask __get and discard if it returns null
- elseif (method_exists($base, '__get')) {
+ if (method_exists($base, '__get')) {
 $tmp = $base->$current;
 if (null !== $tmp) {
 $base = $tmp;

#Terin Stock
Undergraduate, Computer Science (CISE), University of Florida
PHPTAL mailing list

Reply via email to