It's different because I, as a Perl programmer, don't have to worry about the next function name I choose colliding with any of over 3000 built-ins or any function defined in any file I might ever want to include.
| [reply] |
<?php
class foo {
function hello() {
print "hello world\n";
}
}
class bar {
function hello() {
print "greetings planetary body\n";
}
}
foo::hello();
bar::hello();
?>
Can't you treat PHP classes like Perl packages?
(Disclaimer: I'm not a PHP coder so I'm probably missing something blatant ;-) | [reply] [d/l] |
package Foo;
use LWP::Simple qw(get);
my $content = get('http://perlmonks.org/');
This imports the 'get' function into the 'Foo' namespace without trampling functions called 'get' in other namespaces. There is no equivalent to this in PHP because there is only namespace. You would always have to call all class methods by their fully-qualified names. That may not sound annoying until you consider some short and popular function names like try/catch. In Perl, you can define 'try' to mean one thing in one class and another thing in another, but not in PHP. This also means that if you want to override 'exit' in a certain place to do something special, you can do it in Perl but not in PHP.
So, PHP5 classes look like they will help with isolation if you can stick with OO throughout, but are ultimately not as flexible as Perl's namespaces. | [reply] [d/l] [select] |