Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] namespace separator ideas [RSS Feed]

#1 Nov. 26, 2005 20:53:44

Greg B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] namespace separator ideas


Hi all,

I have only one caveat with the \ separator, which is that it is a
little bit too similar to division with /, and can result in some
confusing code like:

<?php
namespace name1 {
class name2{}
}
define('name1', 1);
define('name2', 2);

$a = new name1\name2;
$b = name1/name2;
?>

The same issue exists with all colon based separators (that sounds bad
when read the wrong way...) because of the ternary operator, and :: with
static classes/methods.

<?php
namespace name1 {
class name2{}
}
define('name1', 1);
define('name2', 2);
// this may be a parse error with the current namespace patch,
// but need not be if we use ->
class name1
{
const name2 = 1;
}

$a = new name1:::name2;
$b = name1::name2; // do you see the difference? I get confused
?>

What about using the T_OBJECT_OPERATOR? This is a parse error in
existing versions, and also implies some separation.

<?php
namespace name1 {
class name2{}
}
define('name1', 1);
define('name2', 2);
// this may be a parse error with the current namespace patch,
// but need not be if we use ->
class name1
{
const name2 = 1;
}

$a = new name1->name2;
$b = name1::name2;
?>

I also proposed on IRC using \\ as this is similar to netware driver
separators:

<?php
define('name1', 1);
define('name2', 2);

$a = new name1\\name2;
$b = name1/name2;
?>

However, I know Andrei hated this :). I very much prefer the use of ->,
as this has the same advantage as :: of "rhyming" with current syntax.

Greg

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Nov. 26, 2005 21:37:19

Jared W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] namespace separator ideas


> Hi all,
>
> I have only one caveat with the \ separator, which is that it
> is a little bit too similar to division with /, and can
> result in some confusing code like:
>
> <?php
> namespace name1 {
> class name2{}
> }
> define('name1', 1);
> define('name2', 2);
>
> $a = new name1\name2;
> $b = name1/name2;
> ?>
>
> The same issue exists with all colon based separators (that
> sounds bad when read the wrong way...) because of the ternary
> operator, and :: with static classes/methods.
>
> <?php
> namespace name1 {
> class name2{}
> }
> define('name1', 1);
> define('name2', 2);
> // this may be a parse error with the current namespace
> patch, // but need not be if we use -> class name1 {
> const name2 = 1;
> }
>
> $a = new name1:::name2;
> $b = name1::name2; // do you see the difference? I get confused ?>
>
> What about using the T_OBJECT_OPERATOR? This is a parse
> error in existing versions, and also implies some separation.
>
> <?php
> namespace name1 {
> class name2{}
> }
> define('name1', 1);
> define('name2', 2);
> // this may be a parse error with the current namespace
> patch, // but need not be if we use -> class name1 {
> const name2 = 1;
> }
>
> $a = new name1->name2;
> $b = name1::name2;
> ?>
>
> I also proposed on IRC using \\ as this is similar to netware driver
> separators:
>
> <?php
> define('name1', 1);
> define('name2', 2);
>
> $a = new name1\\name2;
> $b = name1/name2;
> ?>
>
> However, I know Andrei hated this :). I very much prefer the
> use of ->, as this has the same advantage as :: of "rhyming"
> with current syntax.

Hi,
I was thinking -> too.. Had ideas of namespaces being object instances
in their own right..

namespace foo { const ACONST = '1'; class bar {} }

echo $foo->bar; // some mangled internal class name
(foo_bar_123 or something) to make it unique
$a = new $foo->bar();
$ref = new ReflectionClass($foo->bar);



Jared

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Nov. 26, 2005 21:40:40

Jason G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] namespace separator ideas


Hello,

I as a userland library author, would appreciate namespaces quite a
bit. Here is an idea:

namespace1..class()

$x = new MyApp..MemberOrder();


--
Best regards,
Jason

Saturday, November 26, 2005, 3:52:35 PM, you wrote:

GB> Hi all,

GB> I have only one caveat with the \ separator, which is that it is a
GB> little bit too similar to division with /, and can result in some
GB> confusing code like:

GB> <?php
GB> namespace name1 {
GB> class name2{}
GB> }
GB> define('name1', 1);
GB> define('name2', 2);

GB> $a = new name1\name2;
GB> $b = name1/name2;
?>>

GB> The same issue exists with all colon based separators (that sounds bad
GB> when read the wrong way...) because of the ternary operator, and :: with
GB> static classes/methods.

GB> <?php
GB> namespace name1 {
GB> class name2{}
GB> }
GB> define('name1', 1);
GB> define('name2', 2);
GB> // this may be a parse error with the current namespace patch,
GB> // but need not be if we use ->
GB> class name1
GB> {
GB> const name2 = 1;
GB> }

GB> $a = new name1:::name2;
GB> $b = name1::name2; // do you see the difference? I get confused
?>>

GB> What about using the T_OBJECT_OPERATOR? This is a parse error in
GB> existing versions, and also implies some separation.

GB> <?php
GB> namespace name1 {
GB> class name2{}
GB> }
GB> define('name1', 1);
GB> define('name2', 2);
GB> // this may be a parse error with the current namespace patch,
GB> // but need not be if we use ->
GB> class name1
GB> {
GB> const name2 = 1;
GB> }

$a = new name1->>name2;
GB> $b = name1::name2;
?>>

GB> I also proposed on IRC using \\ as this is similar to netware driver
GB> separators:

GB> <?php
GB> define('name1', 1);
GB> define('name2', 2);

GB> $a = new name1\\name2;
GB> $b = name1/name2;
?>>

GB> However, I know Andrei hated this :). I very much prefer the use of ->,
GB> as this has the same advantage as :: of "rhyming" with current syntax.

GB> Greg

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] namespace separator ideas [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support