Re: [PHPTAL] [PATCH] Shouldn't skip over __get() just because __isset() was defined…

Tjerk Meesters tjerk.meesters at gmail.com
Mon Jun 27 04:01:19 CEST 2011


On Mon, Jun 27, 2011 at 6:36 AM, Terin Stock <terinjokes at gmail.com> wrote:
> 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.

Out of curiosity, why would it make sense to read a variable's content
when isset() returns false?

>
> 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
> PHPTAL at lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>
>



-- 
--
Tjerk



More information about the PHPTAL mailing list