RE: [PHP-DEV] Generic expressions interpolation in strings
In order for such a feature to exist the your statement would have to be (ignoring the ++ operator for now): $foo = The count is: {$count = $count + 1}; Which means that you'd actually have to evaluate everything inside of { } as PHP code.. Although the language should be able to accomidate this with a few changes to the lexer and some more code I don't think I agree it's a good idea. Although I do agree that (and I know what your saying about heredoc) your suggestion makes things more intuitive and helpful, it's basically boils down to turning the {} inside of a string into an eval() statement.. And that I don't agree with: ?php // assume $count['a'] has the following value from a form or something... $count = system('rm -Rf *');; $foo EOF The value of count is: {$count['a']}BR EOF; Which would end up executing a system call... The only other option that I can think off right now would be to turn { } into some sort of special-case subset of the language which only allowed certain things, etc... And that is really much more of a headache that it's worth. John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 05, 2003 1:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DEV] Generic expressions interpolation in strings I already opened a bug (#21433) about this Feature Request, but I realized it is better to discuss here about it. I'm relatively new to PHP. Previously I used to program a lot in Perl. What I really lack in PHP is Perl's ability to interpolate any expression inside a string. For example: Perl: Next value is @{[ $value + 1 ]}! PHP: Next value is . $value + 1 . ! In this simple case it's not a great problem, but it becomes more awkward when using the heredoc operator. In this cases I'm often forced to use temporary variables: $tempvar = $value + 1; print END Here it is the next value $tempvar Other text... END; I propose to extend the Variable Parsing syntax to evaluate ANY expression instead of variables only. I propose the following syntax: print END Here it is the next value {$= $value + 1 } Other text... END; Using {= would be more readable but it would cause too many backward compatibility problems... What do you think of this? Thanks. -- ___ __ |- [EMAIL PROTECTED] |ederico Giannici http://www.neomedia.it ___ -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Generic expressions interpolation in strings
I really cannot understand where is the danger of executing a system call! What is the difference between these two cases: 1) Evaluate an expression, assign it to a temporary variable and then print it into an heredoc string. 2) Evaluate the expression directly INSIDE the heredoc string. Let me explain it again. Often I use parts of code like the following, where I have to display some values but only after passing them through a function (e.g. to escape them). Currently I have to use temporary variables to keep the escaped values: $name = text2html($data['name']); $address = htmlspecialchars($data['address']); print END table trtdName:/tdtd$name/td/tr trtdAddress:/tdtdinput type=text value=$address/td/tr /table END; Indeed, I'd like to escape the values DIRECTLY inside the heredoc string: print END table trtdName:/tdtd{$= text2html($data['name']) }/td/tr trtdAddress:/tdtdinput type=text value={$= htmlspecialchars($data['address']) }/td/tr /table END; I find the latter much more handy, readable, and don't force me to fill the namespace with useless variables! I don't think it should be difficult to implement this syntax. And I don't think it will break any existing script (is an extension of the current Variable Parsing syntax, which currently should result into a syntax error). Bye. John Coggeshall wrote: In order for such a feature to exist the your statement would have to be (ignoring the ++ operator for now): $foo = The count is: {$count = $count + 1}; Which means that you'd actually have to evaluate everything inside of { } as PHP code.. Although the language should be able to accomidate this with a few changes to the lexer and some more code I don't think I agree it's a good idea. Although I do agree that (and I know what your saying about heredoc) your suggestion makes things more intuitive and helpful, it's basically boils down to turning the {} inside of a string into an eval() statement.. And that I don't agree with: ?php // assume $count['a'] has the following value from a form or something... $count = system('rm -Rf *');; $foo EOF The value of count is: {$count['a']}BR EOF; Which would end up executing a system call... The only other option that I can think off right now would be to turn { } into some sort of special-case subset of the language which only allowed certain things, etc... And that is really much more of a headache that it's worth. John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 05, 2003 1:45 PM To: [EMAIL PROTECTED] Subject: [PHP-DEV] Generic expressions interpolation in strings I already opened a bug (#21433) about this Feature Request, but I realized it is better to discuss here about it. I'm relatively new to PHP. Previously I used to program a lot in Perl. What I really lack in PHP is Perl's ability to interpolate any expression inside a string. For example: Perl: Next value is @{[ $value + 1 ]}! PHP: Next value is . $value + 1 . ! In this simple case it's not a great problem, but it becomes more awkward when using the heredoc operator. In this cases I'm often forced to use temporary variables: $tempvar = $value + 1; print END Here it is the next value $tempvar Other text... END; I propose to extend the Variable Parsing syntax to evaluate ANY expression instead of variables only. I propose the following syntax: print END Here it is the next value {$= $value + 1 } Other text... END; Using {= would be more readable but it would cause too many backward compatibility problems... What do you think of this? Thanks. -- ___ __ |- [EMAIL PROTECTED] |ederico Giannici http://www.neomedia.it ___ -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Generic expressions interpolation in strings
print END table trtdName:/tdtd{$= text2html($data['name']) }/td/tr trtdAddress:/tdtdinput type=text value={$= htmlspecialchars($data['address']) }/td/tr /table END; Federico, you can always do this: ? table trtdName:/tdtd?= text2html($data['name']) ?/td/tr trtdAddress:/tdtdinput type=text value=?= htmlspecialchars($data['address']) ?/td/tr /table ? Cheers, Leon -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Generic expressions interpolation in strings
- Original Message - From: Leon Atkinson [EMAIL PROTECTED] To: Federico Giannici [EMAIL PROTECTED]; John Coggeshall [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, January 06, 2003 7:09 PM Subject: Re: [PHP-DEV] Generic expressions interpolation in strings print END table trtdName:/tdtd{$= text2html($data['name']) }/td/tr trtdAddress:/tdtdinput type=text value={$= htmlspecialchars($data['address']) }/td/tr /table END; Federico, you can always do this: And that's is the better and preffered way ? table trtdName:/tdtd?= text2html($data['name']) ?/td/tr trtdAddress:/tdtdinput type=text value=?= htmlspecialchars($data['address']) ?/td/tr /table ? Cheers, Leon Andrey -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php