[PHP] the class as a namespace

2008-05-15 Thread Iv Ray

Is there a notion of the class as a namespace?

My understanding is that the namespaces are intended to help organize 
the classes in large projects (and are not perfect).


Is it considered good style to use a class simply to box related functions?

For instance, a class called files, contains functions I need for 
dealing with files - and the instantiated object is _simply_ used to 
access these functions - the instantiated object is not a file in 
itself. Thus what I do is not $INSTANTIATED_OBJECT-save(), but 
$INSTANTIATED_OBJECT-save($file) (though I could do the first if I 
first, say, do $INSTANTIATED_OBJECT-file = $file.


Accessing the functions using the scope resolution operator (::) avoids 
the need to instantiate an object, but does not allow the use of $this, 
and $this can be quite practical in order to group common logic into 
shared methods within the class and thus make the other methods smaller 
in terms of code (of course, one could use file::save, file::delete 
instead of $this-save and $this-delete, but it makes renaming objects 
more difficult).


I would be interested to hear opinions.

Iv

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] the class as a namespace

2008-05-15 Thread Iv Ray

Richard Heyes wrote:
 That's a common use of static classes. Eg:

 HTTP::Redirect($url);

 In fact this (from the article I've read) is exactly how namespaces will
 look like. So in the above example, HTTP could be either a namespace or
 a class.

Right. Namespaces do look similar. And PEAR employs similarly looking
packages naming convention.

So it seems the static classes (which are actually simply classes with
static methods/properties, right) are the best namespaces like way,
until the namespaces arrive.

Thanks for your note,
Iv

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php