# Namespace problem?

- Thread: https://externals.io/message/38982
- Original archive: https://news-web.php.net/php.internals/38982
- Started by Stefan Priebsch on 2008-07-15T16:08:10+00:00
- Messages: 16
- 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

---

## #38982 — Stefan Priebsch — 2008-07-15T16:08:10+00:00

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

Hi list,

I was playing around with namespaces and stumbled across this:

#!/home/steve/php5.3-200807070430/sapi/cli/php
<?php

  namespace Foo;

  use Foo::Bar as Something;

  class Bar { }

?>

works fine, whereas

#!/home/steve/php5.3-200807070430/sapi/cli/php
<?php

  namespace Foo;
  {
    use Foo::Bar as Something;

    class Bar { }
  }

?>

yields: ﻿Parse error: syntax error, unexpected `T_USE` 
in /home/steve/namespaces/code/with_braces.php on line 6

Regards,

Stefan

-- 
 >e-novative> - We make IT work for you.
 http://www.e-novative.de

 e-novative GmbH - Poignring 24 - 82515 Wolfratshausen - Germany
 tel/phone +49 (0)8171 267 087 0 - fax +49 (0)8171 267 087 5

 Handelsregister/Trade Register: Amtsgericht München HRB 139407
 Sitz/Registered Office:         Wolfratshausen
 Geschäftsführer/Executive:      Dipl. Inform. Stefan Priebsch
                                 GnuPG Key: 0x7DB67F7F

---

## #38999 — Alexey Zakhlestin — 2008-07-16T06:50:39+00:00

URL: https://externals.io/message/38982#38999 · In reply to: #38982

> Hi list,
>
> I was playing around with namespaces and stumbled across this:
>
> #!/home/steve/php5.3-200807070430/sapi/cli/php
> <?php
>
>  namespace Foo;
>
>  use Foo::Bar as Something;
>
>  class Bar { }
>
> ?>
>
> works fine, whereas
>
> #!/home/steve/php5.3-200807070430/sapi/cli/php
> <?php
>
>  namespace Foo;
>  {
>    use Foo::Bar as Something;
>
>    class Bar { }
>  }
>
> ?>
>
> yields: ﻿Parse error: syntax error, unexpected `T_USE` > in /home/steve/namespaces/code/with_braces.php on line 6

"use" is a file-level construct, as far as I remember, so you can't
put it into block

-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #39000 — Hannes Magnusson — 2008-07-16T07:34:53+00:00

URL: https://externals.io/message/38982#39000 · In reply to: #38999

> 
> > […]
>
> "use" is a file-level construct, as far as I remember, so you can't
> put it into block

I thought the only argument against using curly braces for namespaces
was exactly his example "you can use namespace foo; {} if you really
want to"?

-Hannes

---

## #39001 — Alexey Zakhlestin — 2008-07-16T07:41:01+00:00

URL: https://externals.io/message/38982#39001 · In reply to: #39000

On Wed, Jul 16, 2008 at 11:34 AM, Hannes Magnusson
<hannes.magnusson@gmail.com> wrote:
> I thought the only argument against using curly braces for namespaces
> was exactly his example "you can use namespace foo; {} if you really
> want to"?

OK:
namespace foo;
{
}

Not OK:
{
    use Foo:Bar as Something;
}


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #39008 — Stefan Priebsch — 2008-07-16T15:02:07+00:00

URL: https://externals.io/message/38982#39008 · In reply to: #39001

Alexey Zakhlestin schrieb:
> OK:
> namespace foo;
> {
> }
> 
> Not OK:
> {
>     use Foo:Bar as Something;
> }

Then that is a showstopper that effectively does not allow to use braces 
around a namespace, so I'd boldly suggest either fixing the curly braces 
notation to allow use statements or disallow curly braces around 
namespaces, because as it is, it doesn't really seem useful.

Regards,

Stefan

-- 
  >e-novative> - We make IT work for you.

  e-novative GmbH - HR: Amtsgericht München HRB 139407
  Sitz: Wolfratshausen - GF: Dipl. Inform. Stefan Priebsch

  http://www.e-novative.de - GnuPG Key: 0x7DB67F7F

---

## #39009 — Dmitry Stogov — 2008-07-16T15:30:38+00:00

URL: https://externals.io/message/38982#39009 · In reply to: #38982

The "use" can be used only as top-level statement.

Thanks. Dmitry.

Stefan Priebsch wrote:
> Hi list,
> 
> I was playing around with namespaces and stumbled across this:
> 
> #!/home/steve/php5.3-200807070430/sapi/cli/php
> <?php
> 
>   namespace Foo;
> 
>   use Foo::Bar as Something;
> 
>   class Bar { }
> 
> ?>
> 
> works fine, whereas
> 
> #!/home/steve/php5.3-200807070430/sapi/cli/php
> <?php
> 
>   namespace Foo;
>   {
>     use Foo::Bar as Something;
> 
>     class Bar { }
>   }
> 
> ?>
> 
> yields: ﻿Parse error: syntax error, unexpected `T_USE` 
> in /home/steve/namespaces/code/with_braces.php on line 6
> 
> Regards,
> 
> Stefan

---

## #39018 — Stanislav Malyshev — 2008-07-16T19:44:46+00:00

URL: https://externals.io/message/38982#39018 · In reply to: #39008

Hi!

> around a namespace, so I'd boldly suggest either fixing the curly braces 
> notation to allow use statements or disallow curly braces around 

Use statements should be at the top, as the influence whole file scope.

> namespaces, because as it is, it doesn't really seem useful.

What doesn't seem useful? What exactly you are trying to do?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39019 — Stefan Priebsch — 2008-07-16T20:05:51+00:00

URL: https://externals.io/message/38982#39019 · In reply to: #39018

Stanislav Malyshev schrieb:
> Hi!
> 
> > […]
> 
> Use statements should be at the top, as the influence whole file scope.

I know, but namespace must be the first statement in a script, so I 
can't put use _before_ the namespace.

> 
> > […]
> 
> What doesn't seem useful? What exactly you are trying to do?

Trying to use curly braces around my namespace for readability. But I 
can't put a use statement _into_ these namespaces, neither can I put the 
  use _before_ the namespace.

That means: I cannot use namespaces with curly braces combined with a 
use statement. This makes the curly braces pretty pointless.

Regards,

Stefan

-- 
  >e-novative> - We make IT work for you.

  e-novative GmbH - HR: Amtsgericht München HRB 139407
  Sitz: Wolfratshausen - GF: Dipl. Inform. Stefan Priebsch

  http://www.e-novative.de - GnuPG Key: 0x7DB67F7F

---

## #39021 — Stanislav Malyshev — 2008-07-16T20:14:21+00:00

URL: https://externals.io/message/38982#39021 · In reply to: #39019

Hi!

> That means: I cannot use namespaces with curly braces combined with a 
> use statement. This makes the curly braces pretty pointless.

Well, don't use them then :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39023 — Lukas Kahwe Smith — 2008-07-16T20:15:58+00:00

URL: https://externals.io/message/38982#39023 · In reply to: #39021

> Hi!
>
> > […]
>
> Well, don't use them then :)

I think Stefan was just pointing out that allowing something that is  
rarely useful is just needlessly confusing, because it makes you think  
there is something you are missing.

regards,
Lukas Kahwe Smith
mls@pooteeweet.org

---

## #39024 — Stanislav Malyshev — 2008-07-16T20:21:44+00:00

URL: https://externals.io/message/38982#39024 · In reply to: #39023

Hi!

> I think Stefan was just pointing out that allowing something that is 
> rarely useful is just needlessly confusing, because it makes you think 
> there is something you are missing.

It may be true in some cases, but in general PHP allows to do tons of 
stuff that is not useful, or at least does not seem to be useful. But I 
don't think it's productive to spend time on disallowing such things - 
same time could be spent developing real features :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39032 — Stefan Priebsch — 2008-07-17T06:10:31+00:00

URL: https://externals.io/message/38982#39032 · In reply to: #39024

Hi Stas,

Stanislav Malyshev schrieb:
> It may be true in some cases, but in general PHP allows to do tons of 
> stuff that is not useful, or at least does not seem to be useful. But I 
> don't think it's productive to spend time on disallowing such things - 
> same time could be spent developing real features :)

I think it may be more productive to disallow it now, instead of 
bogusifying bug reports and dealing with confused users later. My 2ct.

Regards,

Stefan

-- 
  >e-novative> - We make IT work for you.

  e-novative GmbH - HR: Amtsgericht München HRB 139407
  Sitz: Wolfratshausen - GF: Dipl. Inform. Stefan Priebsch

  http://www.e-novative.de - GnuPG Key: 0x7DB67F7F

---

## #39033 — Stanislav Malyshev — 2008-07-17T06:35:12+00:00

URL: https://externals.io/message/38982#39033 · In reply to: #39032

Hi!

> I think it may be more productive to disallow it now, instead of 
> bogusifying bug reports and dealing with confused users later. My 2ct.

I don't think wasting effort on introducing artificial restrictions into 
PHP just because somebody might erroneously submit a bug report is worth 
doing.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39039 — Alexey Zakhlestin — 2008-07-17T07:46:03+00:00

URL: https://externals.io/message/38982#39039 · In reply to: #39033

> Hi!
>
> > […]
>
> I don't think wasting effort on introducing artificial restrictions into PHP
> just because somebody might erroneously submit a bug report is worth doing.

is it possible to add custom (more user-friendly) error-message in this case?


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #39040 — Stanislav Malyshev — 2008-07-17T08:40:17+00:00

URL: https://externals.io/message/38982#39040 · In reply to: #39039

Hi!

> is it possible to add custom (more user-friendly) error-message in this case?

I don't know. So far we never had custom user-friendly error messages in 
  parser. If you want to do it and know how, you can propose it, but 
then I guess other parser errors should get same treatment.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39056 — Alexey Zakhlestin — 2008-07-17T14:49:14+00:00

URL: https://externals.io/message/38982#39056 · In reply to: #39040

> Hi!
>
> > […]
>
> I don't know. So far we never had custom user-friendly error messages in
>  parser. If you want to do it and know how, you can propose it, but then I
> guess other parser errors should get same treatment.

well, looks like it is not an easy task for bison-parser.
it is worth to look at this problem after switching to lemon (5.4?)


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/
