Let blocks

php.internals

Keryx Web

19 years ago
Hi again! Now that namespaces seem to be on their way into PHP 6 I wonder if let-blocks, as in JavaScript 1.7+, ever has been considered for PHP, to hide global variables from each other? If so, can someone point me to the discussion? For those that might have missed JS 1.7: http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#Block_scope_with_let Lars Gunther

Stanislav Malyshev

19 years ago
> Now that namespaces seem to be on their way into PHP 6 I wonder if > let-blocks, as in JavaScript 1.7+, ever has been considered for PHP, to > hide global variables from each other?
I personally am not convinced that PHP has any need for convoluted scoping rules that "let" creates. What would be a use case that would require such function?
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

Daniel Jänecke

19 years ago
I don't get the point of it. IMO this will only add another level of confusion to sourcecode; unless someone has a real good example (better than those in the posted link) where this technique is required I cannot see which benefit this feature adds. regards danielj Keryx Web wrote:

Keryx Web

19 years ago
Daniel Jänecke skrev:
> I don't get the point of it. IMO this will only add another level of > confusion to sourcecode; unless someone has a real good example (better > than those in the posted link) where this technique is required I cannot > see which benefit this feature adds. >
1. Neither daniel nor Stanislav pointed to a previous discussion. I therefore suppose this topic never has been brought up before. 2. Block scope is part of quite a few languages. Does it serve any purpose in C, C# or Java? Does "my" and "local" serve any purpose in PERL? [1] Heck, even VB.net has block scope![2] I am not saying that PHP must have it just because it exists in other languages - far from it! But it can not be *that* hard to imagine use cases. 3. Why do I think this idea is worth discussing? What is my use case? My main contact with PHP nowadays is teaching it. And my students are usually newbies to web development. Real namespaces is quite a long way away from their understanding. Not everyone is a Bill Joy, a Linus Torvalds or a Rasmus Leerdorf! Many students - and other newbies - will cut and paste as a part of their learning process. So even for more simple procedural code there is a point in being able to hide variables from one snippet to another. I consider block scope a sort of "namespaces light", an easy to understand first step. As JS 2 will have the "let" keyword - and to most newbies JS will be the principal "other" language besides PHP - a similar construct would be easy to grasp. To what extent block scoping would require a rewrite of PHP internally is beyond my grasp. If this would put off the release of PHP 6 by 6 moonths it's not worth it. If it would delay PHP 6 one week, it might be - IMHO. Lars Gunther 1. http://perl.plover.com/FAQs/Namespaces.html#C_local_and_C_my_ 2. http://msdn2.microsoft.com/en-us/library/1t0wsc67(VS.80).aspx

Antony Dovgal

19 years ago
Do you have a patch? On 19.07.2007 16:26, Keryx Web wrote:
> Daniel Jänecke skrev: > > I don't get the point of it. IMO this will only add another level of > > confusion to sourcecode; unless someone has a real good example (better > > than those in the posted link) where this technique is required I cannot > > see which benefit this feature adds. > > > > 1. Neither daniel nor Stanislav pointed to a previous discussion. I > therefore suppose this topic never has been brought up before. > > 2. Block scope is part of quite a few languages. Does it serve any > purpose in C, C# or Java? Does "my" and "local" serve any purpose in > PERL? [1] Heck, even VB.net has block scope![2] > > I am not saying that PHP must have it just because it exists in other > languages - far from it! But it can not be *that* hard to imagine use cases. > > 3. Why do I think this idea is worth discussing? What is my use case? > > My main contact with PHP nowadays is teaching it. And my students are > usually newbies to web development. Real namespaces is quite a long way > away from their understanding. Not everyone is a Bill Joy, a Linus > Torvalds or a Rasmus Leerdorf! > > Many students - and other newbies - will cut and paste as a part of > their learning process. So even for more simple procedural code there is > a point in being able to hide variables from one snippet to another. > > I consider block scope a sort of "namespaces light", an easy to > understand first step. As JS 2 will have the "let" keyword - and to most > newbies JS will be the principal "other" language besides PHP - a > similar construct would be easy to grasp. > > To what extent block scoping would require a rewrite of PHP internally > is beyond my grasp. If this would put off the release of PHP 6 by 6 > moonths it's not worth it. If it would delay PHP 6 one week, it might be > - IMHO. > > > Lars Gunther > > 1. http://perl.plover.com/FAQs/Namespaces.html#C_local_and_C_my_ > 2. http://msdn2.microsoft.com/en-us/library/1t0wsc67(VS.80).aspx >
-- Wbr, Antony Dovgal

Antony Dovgal

19 years ago
> The reason I posted my suggestions on this list was that a while ago I > had a few ideas as to how PHP could be improved. A seasoned PHP > developer suggested that I'd take my suggestions to this list.
Thanks a lot for your suggestions, but (as you can see from the list) we have a lot of other things to do and adding new pretty looking features from other languages is the last thing in my personal TODO list. There are two ways to add a new feature I know of: 1) to convince the developers that it's terribly critical to have this feature (which I doubt is possible) or rouse their interest in some other way; 2) to do it yourself, probably with some help from the developers. I believe the second way is and will stay the best ever. And it's not about your CVS karma, this is how Open Source works. Also, every time you suggest a new feature, you should remember that it would appear on shared hostings in no less than 3-5 years. This is quite critical issue for most of the people, but they tend to forget about it.
-- Wbr, Antony Dovgal

Stanislav Malyshev

19 years ago
> 2. Block scope is part of quite a few languages. Does it serve any
purpose in C, C# or Java? Does "my" and "local" serve any purpose in PERL? [1] Funny that you ask, because Perl docs you linked specifically say "local" does not serve any real purpose, is extremely confusing and they have it only for BC reasons. "my" does serve a purpose, but in Perl scopes are a bit different from PHP (anonymous functions, etc.) so per-scope local variables make more sense.
> I am not saying that PHP must have it just because it exists in other > languages - far from it! But it can not be *that* hard to imagine use > cases.
If it isn't so hard to imagine them, it shouldn't be hard to post them, right? ;)
> My main contact with PHP nowadays is teaching it. And my students are > usually newbies to web development. Real namespaces is quite a long way > away from their understanding. Not everyone is a Bill Joy, a Linus > Torvalds or a Rasmus Leerdorf!
That's one reason why we work hard to keep the language simple, while on the other hand trying to make it powerful enough to be useful. These are contradicting goals, so finding a balance between them is not easy. That's why new features must be carefully weighted - how much complication does it add? How much power? Is is worth it? Naturally, if one proposes something, it is expected that he'd make the first argument towards proving the worthiness - which may or may not be supported by the community.
> Many students - and other newbies - will cut and paste as a part of > their learning process. So even for more simple procedural code there is > a point in being able to hide variables from one snippet to another.
function? :)
> I consider block scope a sort of "namespaces light", an easy to > understand first step. As JS 2 will have the "let" keyword - and to most > newbies JS will be the principal "other" language besides PHP - a > similar construct would be easy to grasp.
I seriously doubt that many newbies need Javascript features that appeared only in 1.7 - such as let blocks with advanced scoping rules - or really understand them. Javascript is rather complicated (and powerful) language - definitely more complicated than PHP, IMHO.
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

Tijnema !

19 years ago
On 7/19/07, Stanislav Malyshev <stas@zend.com> wrote: <snip>
> > I consider block scope a sort of "namespaces light", an easy to > > understand first step. As JS 2 will have the "let" keyword - and to most > > newbies JS will be the principal "other" language besides PHP - a > > similar construct would be easy to grasp. > > I seriously doubt that many newbies need Javascript features that > appeared only in 1.7 - such as let blocks with advanced scoping rules - > or really understand them. Javascript is rather complicated (and > powerful) language - definitely more complicated than PHP, IMHO. > -- > Stanislav Malyshev, Zend Software Architect > stas@zend.com http://www.zend.com/ > (408)253-8829 MSN: stas@zend.com
I don't even think that "experts" will use it, since it will take ages before Microsoft has updated IE to work with 1.7. I guess it will not be implemented before IE8, and since the migration to IE7 goes already very slow, it won't be earlier than 2009 before the biggest part of the people uses an JS 1.7 compliant browser (IE8/FF2/...) Tijnema
-- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

chris#

19 years ago
On Thu, 19 Jul 2007 23:16:33 +0200, Tijnema <tijnema@gmail.com> wrote:
> On 7/19/07, Stanislav Malyshev <stas@zend.com> wrote: > <snip> >> > I consider block scope a sort of "namespaces light", an easy to >> > understand first step. As JS 2 will have the "let" keyword - and to > most >> > newbies JS will be the principal "other" language besides PHP - a >> > similar construct would be easy to grasp. >> >> I seriously doubt that many newbies need Javascript features that >> appeared only in 1.7 - such as let blocks with advanced scoping rules - >> or really understand them. Javascript is rather complicated (and >> powerful) language - definitely more complicated than PHP, IMHO. >> -- >> Stanislav Malyshev, Zend Software Architect >> stas@zend.com http://www.zend.com/ >> (408)253-8829 MSN: stas@zend.com > > I don't even think that "experts" will use it, since it will take ages > before Microsoft has updated IE to work with 1.7. I guess it will not > be implemented before IE8,
FWIW, It is my understanding that the next slated version of IE is to be: IE NEXT. It is a promisary(sp) venture between M$ and some standards groups (whos name(s) I cannot recall at the momment) to provide a fully Standards based browser which will also adhere to the current Accessibility standards. If any of this helps.
> and since the migration to IE7 goes already > very slow, it won't be earlier than 2009 before the biggest part of > the people uses an JS 1.7 compliant browser (IE8/FF2/...) > > Tijnema > -- > Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
///////////////////////////////////////////////////// Service provided by hitOmeter.NET internet messaging! .