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.


In reply to Re^7: Perl vs. PHP by perrin
in thread Perl vs. PHP by nikos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.