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
Hi list,
I was playing around with namespaces and stumbled across this:
#!/home/steve/php5.3-200807070430/sapi/cli/php
<?phpnamespace Foo;
use Foo::Bar as Something;
class Bar { }
?>
works fine, whereas
#!/home/steve/php5.3-200807070430/sapi/cli/php
<?phpnamespace 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/
Hi list,
I was playing around with namespaces and stumbled across this:
#!/home/steve/php5.3-200807070430/sapi/cli/php
<?phpnamespace Foo;
use Foo::Bar as Something;
class Bar { }
?>
works fine, whereas
#!/home/steve/php5.3-200807070430/sapi/cli/php
<?phpnamespace 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
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
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/
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
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
Stanislav Malyshev schrieb:
Hi!
around a namespace, so I'd boldly suggest either fixing the curly
braces notation to allow use statements or disallow curly braces aroundUse 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.
namespaces, because as it is, it doesn't really seem useful.
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
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
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 :)
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
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
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
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
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.
is it possible to add custom (more user-friendly) error-message in this case?
--
Alexey Zakhlestin
http://blog.milkfarmsoft.com/
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
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.
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/
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
<?phpnamespace Foo;
use Foo::Bar as Something;
class Bar { }
?>
works fine, whereas
#!/home/steve/php5.3-200807070430/sapi/cli/php
<?phpnamespace 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 6Regards,
Stefan