# Let blocks

- Thread: https://externals.io/message/31059
- Original archive: https://news-web.php.net/php.internals/31059
- Started by Keryx Web on 2007-07-18T18:25:57+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #31059 — Keryx Web — 2007-07-18T18:25:57+00:00

URL: https://externals.io/message/31059#31059

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

---

## #31060 — Stanislav Malyshev — 2007-07-18T18:37:04+00:00

URL: https://externals.io/message/31059#31060 · In reply to: #31059

> 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

---

## #31061 — jaenecke@gmx.li — 2007-07-18T18:38:52+00:00

URL: https://externals.io/message/31059#31061 · In reply to: #31059

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:
> 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

---

## #31104 — Antony Dovgal — 2007-07-19T14:17:10+00:00

URL: https://externals.io/message/31059#31104

> 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

---

## #31112 — Stanislav Malyshev — 2007-07-19T21:04:13+00:00

URL: https://externals.io/message/31059#31112

> 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

---

## #31114 — Tijnema — 2007-07-19T21:16:33+00:00

URL: https://externals.io/message/31059#31114 · In reply to: #31112

<snip>
> > […]
>
> 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
