Re: [SMARTY] Calling object methods
| From: | Michal Frackowiak | Date: | Thu, 14 Jul 2005 10:07:56 +0000 |
| Subject: | Re: [SMARTY] Calling object methods | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12805@lists.php.net to get a copy of this message | ||
I have a fast fix for smarty to handle {$foo->bar()->display()}.
It is just fine to change the pattern matching in a few lines and it
works - I have tested it and use it it OZONE (www.ozoneframework.org -
but not released yet)
simpy change $this->_obj_start_regexp and $this->_obj_call_regexp in
Smarty_Compiler.class.php to
these given below:
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' .
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
$this->_obj_ext_regexp . '(?:'.$this->_obj_params_regexp.')?'.
')+)';
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' .
$this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp .
'|' . $this->_dvar_math_var_regexp . ')*)?)';
it works for me. no other changes were required as far as I remember.
best regards - michal frackowiak
Joe Stump wrote:
Wait. I'm confused. {$foo->bar()->display()} would break backwards compatibility, but rewriting Smarty for PHP5 wouldn't? Plus, how would allowing for {$foo->bar()->display()} break Smarty's ability to run on PHP4? It would only break that template's ability to run on PHP4. I see a few solutions here: 1.) Just make it so Smarty can handle PHP5 dereferencing. This would, of course, break the templates (again, not Smarty itself), if they were ran under PHP4. 2.) Have two versions of Smarty (2.x is PHP4, 3.x is PHP5). I'm sure this is probably already in progress to some degree (PHPUnit and phpDocumentor both have dual versions out right now). The fact still remains - Smarty is broken under certain circumstances for PHP5. To get around this problem you will have to do the following: {assign var="bar" value=$foo->getClass()} {$bar->display()} --Joe-- -------------------------------------------------------- Michal Frackowiak mail: michalf@ncac.torun.pl www: http://www.ncac.torun.pl/~michalf jabber im: michal_frackowiak@jabber.org phone: +48 (56) 6219319 int. 22, fax: +48 (56) 6219381 -------------------------------------------------------- Nicolaus Copernicus Astronomical Center Department of Astrophysics in Torun (CAMK Torun) ul. Rabianska 8, 87-100 Torun, Poland http://www.ncac.torun.pl, http://www.camk.edu.pl --------------------------------------------------------
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc