Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Richard Quadling
On 15 June 2011 17:23, Stas Malyshev smalys...@sugarcrm.com wrote:
 Hi!

 With pecl/http (DEV-2 branch) and the Functional extension (on github)
 both creating namespaces within the extension, I think there is a
 requirement for a mechanism to allow an extension to record the
 namespace(s) that it has, in a similar fashion to how functions and
 classes are known to core.

 There's no such thing as registered namespaces, at least in the engine.
 Namespace is just a part of class/function name. You could enumerate
 classes/functions and split their names, but I'm not sure for what such list
 will be useful. Could you explain?

 But, trawling all the classes and functions, extracting and
 aggregating the namespace would really not seem to be the way to go.
 And that wouldn't take into account the user defined namespaces.

 Again, there's no such thing as list of user defined namespaces, at runtime.
 You'd have to go through all classes/functions and split their names. Again,
 I'm not sure what would be the use of it.

Currently, I can find the names of functions, classes and interfaces -
be they from an extension or userland code.

But I can't get namespaces, or their aliases.


I'm not totally sure of any other use. That's why I was asking.

As (or if) more extensions start to use namespaces to protect their
contents from name collision, we are probably going to have namespace
collision before long.



-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Richard Quadling
On 16 June 2011 14:03, Martin Scotta martinsco...@gmail.com wrote:

  Martin Scotta


 On Thu, Jun 16, 2011 at 9:40 AM, Richard Quadling rquadl...@gmail.com
 wrote:

 On 15 June 2011 17:23, Stas Malyshev smalys...@sugarcrm.com wrote:
  Hi!
 
  With pecl/http (DEV-2 branch) and the Functional extension (on github)
  both creating namespaces within the extension, I think there is a
  requirement for a mechanism to allow an extension to record the
  namespace(s) that it has, in a similar fashion to how functions and
  classes are known to core.
 
  There's no such thing as registered namespaces, at least in the
  engine.
  Namespace is just a part of class/function name. You could enumerate
  classes/functions and split their names, but I'm not sure for what such
  list
  will be useful. Could you explain?
 
  But, trawling all the classes and functions, extracting and
  aggregating the namespace would really not seem to be the way to go.
  And that wouldn't take into account the user defined namespaces.
 
  Again, there's no such thing as list of user defined namespaces, at
  runtime.
  You'd have to go through all classes/functions and split their names.
  Again,
  I'm not sure what would be the use of it.

 Currently, I can find the names of functions, classes and interfaces -
 be they from an extension or userland code.

 But I can't get namespaces, or their aliases.


 I'm not totally sure of any other use. That's why I was asking.

 As (or if) more extensions start to use namespaces to protect their
 contents from name collision, we are probably going to have namespace
 collision before long.


 that's why naming convention are meant for?

Maybe, but because of a lack of convention on naming, we have namespaces.

It people named their classes/functions/etc with sensible long names,
containing something that was unique to their project, after doing
plenty of research for similar sounding names, we wouldn't need
namespaces.


When/if github/functional and/or pecl/http-DEV2 go live, these will be
the first 2 namespaces provided by PHP extensions (that could be in
general use).

Are you all saying that the potential for a naming-collision is negligible?

It seems so.


As I see it, a namespace is a container. Like a class acts as a
container for methods and properties, so a namespaces acts as a
container for classes, interfaces and functions, ring-fencing them to
avoid name collisions.

So it would seem appropriate to have the ability to investigate a
namespace to see what it contains and/or if it exists.

Why? For exactly the same reasons you have class_exists(),
interface_exists(), function_exists().







-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Stas Malyshev

Hi!

On 6/16/11 8:37 AM, Richard Quadling wrote:

Maybe, but because of a lack of convention on naming, we have namespaces.


No, we have namespaces not because we couldn't agree on naming 
convention, but because any naming convention without namespaces would 
lead to ugly code (which you call sensible long names but which 
rapidly stop being sensible if you actually try to do it).



So it would seem appropriate to have the ability to investigate a
namespace to see what it contains and/or if it exists.

Why? For exactly the same reasons you have class_exists(),
interface_exists(), function_exists().


Classes and functions actually exist as objects in the engine. 
Namespaces do not. They are just parts of names. You can not instantiate 
a namespace, you can not call a namespace. So these reasons do not apply.

--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Stas Malyshev

Hi!


Currently, I can find the names of functions, classes and interfaces -
be they from an extension or userland code.

But I can't get namespaces, or their aliases.


Names of functions and classes _are_ namespaces. As for aliases, these 
are purely compile-time concepts, so there's nothing to get in runtime.


--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Richard Quadling
On 16 June 2011 17:40, Stas Malyshev smalys...@sugarcrm.com wrote:
 Hi!

 On 6/16/11 8:37 AM, Richard Quadling wrote:

 Maybe, but because of a lack of convention on naming, we have namespaces.

 No, we have namespaces not because we couldn't agree on naming convention,
 but because any naming convention without namespaces would lead to ugly code
 (which you call sensible long names but which rapidly stop being sensible
 if you actually try to do it).

I was joking.


 So it would seem appropriate to have the ability to investigate a
 namespace to see what it contains and/or if it exists.

 Why? For exactly the same reasons you have class_exists(),
 interface_exists(), function_exists().

 Classes and functions actually exist as objects in the engine. Namespaces do
 not. They are just parts of names. You can not instantiate a namespace, you
 can not call a namespace. So these reasons do not apply.


And now I understand. Thanks for that.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Ferenc Kovacs
On Thu, Jun 16, 2011 at 7:48 PM, Richard Quadling rquadl...@gmail.comwrote:

 On 16 June 2011 17:40, Stas Malyshev smalys...@sugarcrm.com wrote:
  Hi!
 
  On 6/16/11 8:37 AM, Richard Quadling wrote:
 
  Maybe, but because of a lack of convention on naming, we have
 namespaces.
 
  No, we have namespaces not because we couldn't agree on naming
 convention,
  but because any naming convention without namespaces would lead to ugly
 code
  (which you call sensible long names but which rapidly stop being
 sensible
  if you actually try to do it).

 I was joking.

 
  So it would seem appropriate to have the ability to investigate a
  namespace to see what it contains and/or if it exists.
 
  Why? For exactly the same reasons you have class_exists(),
  interface_exists(), function_exists().
 
  Classes and functions actually exist as objects in the engine. Namespaces
 do
  not. They are just parts of names. You can not instantiate a namespace,
 you
  can not call a namespace. So these reasons do not apply.


 And now I understand. Thanks for that.


Okay, so namespaces doesn't exists for the engine, because they are added to
the classnames in compile-time, but we could add some --rX argument for the
php binary, which would iterate over the classes and functions and so for a
given extension, and fetch and list the introduced namespaces.
what do you think?

Tyrael


Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Johannes Schlüter
On Thu, 2011-06-16 at 19:54 +0200, Ferenc Kovacs wrote:
 Okay, so namespaces doesn't exists for the engine, because they are added to
 the classnames in compile-time, but we could add some --rX argument for the
 php binary, which would iterate over the classes and functions and so for a
 given extension, and fetch and list the introduced namespaces.
 what do you think?

The --rX things are reflection shortcuts, while we have one exception
(--ri) I actually don't want to pollute the options list. I don't see
the need for this. I don't really know when I need to know this
information. What is the worth?

For the one time this is needed one can use a trivial (g)awk command or
such ..

  $ php --re http | awk '/Class \[.+ class .+\\/ { print gensub(/(.*)\\[^\\]+/, 
\\1, 1, $5); }'

should be simple to extend for functions, too. For some maybe more
readable as PHP script. But I still don't get when I'd need that
information.

johannes



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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Stas Malyshev

Hi!


Okay, so namespaces doesn't exists for the engine, because they are
added to the classnames in compile-time, but we could add some --rX
argument for the php binary, which would iterate over the classes and
functions and so for a given extension, and fetch and list the
introduced namespaces.
what do you think?


Well, we could - you could actually do it right now with list of classes 
and some simple regexp-ing. The question is a value of it.

--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-16 Thread Lars Schultz

Am 16.06.2011 20:12, schrieb Stas Malyshev:

Well, we could - you could actually do it right now with list of classes
and some simple regexp-ing. The question is a value of it.


I think get_declared_classes works as well, if you create a script that 
loads all your classes you could then extract all namespaces...(btw. I 
love the way the autoloader plays in concert with the /-Separator, 
thanks for that;)



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



[PHP-DEV] Getting a list of registered namespaces.

2011-06-15 Thread Richard Quadling
Hi.

With pecl/http (DEV-2 branch) and the Functional extension (on github)
both creating namespaces within the extension, I think there is a
requirement for a mechanism to allow an extension to record the
namespace(s) that it has, in a similar fashion to how functions and
classes are known to core.

On the surface, the namespace seems to be consumed by the class name
or function name.

ReflectionClass and ReflectionFunciton both have a getNamespaceName()
method, but there is no corresponding method for ReflectionExtension,
which would need to getNamespaceNames() as an extension could
potentially register multiple namespaces - maybe nested ones.

In both of these methods, the namespace is simply extracted from the
current entity name, but without a way of recording the namespace(s)
provided by an extension.

I think the following should exist

array get_declared_namespaces ( [ bool $categorize = false ] ) Returns
the namespaces currently defined. If categorized, the namespaces are
categorised by the extension that loads them or with a key of 'user'
for user defined namespaces.

and

array ReflectionExtension::getNamespaces() Returns the namespaces for
the extension being reflected.


And I think that phpinfo() should output a Registered Namespaces
right at the top of the page, alongside the Registered Streams.


But, trawling all the classes and functions, extracting and
aggregating the namespace would really not seem to be the way to go.
And that wouldn't take into account the user defined namespaces.


So, (unless I'm mistaken and missing something), an extension needs to
record its namespaces somewhere along with userland namespaces.

Initially, I thought that putting a pointer to a list in
zend_module_entry would be enough to allow the php core code to pick
it up from the extension, but that would need to be at a suitable
version change rather than mid-cycle.

But really, this is out of my depth now.


Maybe a mentor/mentee would be useful here.


Regards,

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP-DEV] Getting a list of registered namespaces.

2011-06-15 Thread Stas Malyshev

Hi!


With pecl/http (DEV-2 branch) and the Functional extension (on github)
both creating namespaces within the extension, I think there is a
requirement for a mechanism to allow an extension to record the
namespace(s) that it has, in a similar fashion to how functions and
classes are known to core.


There's no such thing as registered namespaces, at least in the 
engine. Namespace is just a part of class/function name. You could 
enumerate classes/functions and split their names, but I'm not sure for 
what such list will be useful. Could you explain?



But, trawling all the classes and functions, extracting and
aggregating the namespace would really not seem to be the way to go.
And that wouldn't take into account the user defined namespaces.


Again, there's no such thing as list of user defined namespaces, at 
runtime. You'd have to go through all classes/functions and split their 
names. Again, I'm not sure what would be the use of it.


--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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