Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Perl vs. PHP

by adrianh (Chancellor)
on Aug 14, 2004 at 10:34 UTC ( [id://382934]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl vs. PHP
in thread Perl vs. PHP

Classes are better, but they still have no namespaces. Everything is in one global namespace.

Just being devils advocate for a minute: How is this different from Perl?

Perl mangles the package and class concepts together - it doesn't really have namespaces either (in the sense they are used in C#, C++, Smalltalk, etc.)

Replies are listed 'Best First'.
Re^5: Perl vs. PHP
by chromatic (Archbishop) on Aug 14, 2004 at 16:48 UTC

    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.

      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.

      Don't PHP classes solve exactly that problem? For example:

      <?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 ;-)

        I'm a dilettante too when it comes to PHP, but here's my take on it. You could consider the PHP form of class-naming as equivalent to the Perl form: new MyCompany_Model_ShoppingCart_Persistent in PHP vs. MyCompany::Model::ShoppingCart::Persistent->new() in Perl. In both cases, the name does not actually affect the inheritance, or the visibility of other classes. I consider the Perl one easier to read and organize since the naming implies a directory structure, but that's not such a big deal.

        It becomes a bigger deal when you get into non-OO stuff. In Perl, you can do something like this:

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://382934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found