Re: [SMARTY] Re: object calls fail after upgrade to 2.6.4
| From: | Monte Ohrt | Date: | Thu, 09 Sep 2004 18:20:08 +0000 |
| Subject: | Re: [SMARTY] Re: object calls fail after upgrade to 2.6.4 | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.dev php.smarty.general |
| Request: | Send a blank email to php-smarty-dev+get-2553@lists.php.net to get a copy of this message | ||
I committed CVS the ability to put objects in arbitrary parameter positions. See if that works, and thanks for testing.
hans wrote:
Hi Monte, On Thu, 9 Sep 2004, Monte Ohrt wrote:The reason objects as parameters to objects was not allowed is because PCRE does not support infinite recursion, and this would certainly not be practical to parse: {$foo->bar($foo->bar($foo->bar(...)))}Oh yes, I see. If only PHP had a Parse::RecDescent as Perl has :-)However, since there is code relying on these little discrepancies, I have just committed to CVS the ability to do one level of object nesting. So, this is valid syntax: {$foo->bar($foo->bar))} {$foo->bar($foo->bar()))} {$foo->bar($foo->bar($foo)))} {$foo->bar($foo->bar($foo,$bar.blah,0))} However this is NOT permitted: {$foo->bar($foo->bar($foo->bar)))}This is very good news! One level should be sufficient.Please test and let me know if there are problems.It looks pretty good now. I could only find one case that is still causing a parser error: {$obj->meth("foo", $obj->val)} To make your life easier, I have extended the testcase that I sent earlier today. It includes the above failing case. Maybe it could be integrated in the unit test suite. A last word: thank you very much for your quick help on this matter. It is very much appreciated. Hans !DSPAM:41408e9f221728588224860! ------------------------------------------------------------------------ Index: unit_test/test_cases.php =================================================================== RCS file: /repository/smarty/unit_test/test_cases.php,v retrieving revision 1.7 diff -u -r1.7 test_cases.php--- unit_test/test_cases.php 12 Apr 2004 12:21:39 -0000 1.7 +++ unit_test/test_cases.php 9 Sep 2004 17:03:17 -0000@@ -3,6 +3,16 @@ require_once './config.php'; require_once SMARTY_DIR . 'Smarty.class.php'; require_once 'PHPUnit.php'; + +class Obj {+ var $val = 'val'; + var $arr = array('one' => 'one');++ function meth($a="a", $b="b") { + return "$a:$b"; + }+} + class SmartyTest extends PHPUnit_TestCase {// contains the object handle of the string class@@ -230,6 +240,22 @@$this->smarty->assign('foo', 'bar'); $this->assertEquals($this->smarty->fetch('assign_var.tpl'), 'bar'); }++ // test assigning and calling an object + function test_obj_meth() { + $obj = new Obj(); + $this->smarty->assign('obj', $obj); + $this->smarty->assign('foo', 'foo'); + $this->assertEquals(+'foo:2.5 +2.5:foo +2.5:b +val:foo +foo:val +foo:foo +one:2 +foo:foo:b', $this->smarty->fetch('assign_obj.tpl'));+ }/* CONFIG FILE TESTS */unit_test/templates/assign_var.tpl =================================================================== {$obj->meth($foo, 2.5)} {$obj->meth(2.5, $foo)} {$obj->meth(2.5)} {$obj->meth($obj->val, "foo")} {$obj->meth("foo", $obj->val)} {$obj->meth("foo", $foo)} {$obj->meth($obj->arr.one, 2)} {$obj->meth($obj->meth("foo", $foo))}