Re: [SMARTY] Calling object methods
Michal Frackowiak <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
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 . '(?:' .
$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: [email protected]
www: http://www.ncac.torun.pl/~michalf
jabber im: [email protected]
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
--------------------------------------------------------
signature.asc
(application/pgp-signature, 256 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC1jl8i/c8WOJoItYRAhMlAJ4iiuLze5OIJRM7IUt+EVYzT1Y6tACfZiPx fnKUbke+3icJzWSV4XpjoAE= =+vt6 -----END PGP SIGNATURE-----