in reply to Re: php + Smarty looks like CGI
in thread php + Smarty looks like CGI

As a newbie to both PHP and perl, I'd like to see a truly objective (Note: may not exist) comparison of the two. I think there must be areas where one has strengths over the other. If any such comparisn exists, though, I've yet to find it.

Replies are listed 'Best First'.
Re: Re: Re: php + Smarty looks like CGI
by broquaint (Abbot) on May 18, 2003 at 12:28 UTC
    I've written what I hope to be a fairly objective comparison of Perl and PHP in Re: Preaching Perl gospel to PHP converts.... But further to that here's a simple list of the various differences between the two languages

    Perl PHP
    Language features
    Lexical scoping and dynamic scoping Functions have unique scopes
    3 different contexts (scalar, list, void) No context types
    5 different sigils - $,@,%,&,* One sigil - $
    Regular expressions part of the language Regular expressions accessable through functions
    Data
    Scalars, Arrays, Hashes Scalars, Arrays/Hash duality
    Type-ignorant with roughly 3 types (string, number, reference) Type-ignorant with roughly 13 different types (see. is_ functions)
    Explicit references Optional explicit references
    Pass by value Implicit (i.e it should do the right thing)
    Functions
    Can be called with 3 different syntaxes Called with one syntax
    Anonymous functions part of the language Anonymous functions from create_function
    Can be referenced Symbolic calls
    Args implicitly aliased to @_ Named args
    Objects
    Created through blessing a reference Created through new Class
    Multiple Inheiritance Single Inheritance
    Class variables aren't standard Class variables part of the language

    This is by no means exhaustive or entirely accurate but should give you some ideas of the fundamental differences between the two languages.
    HTH

    _________
    broquaint

      1. "Pass by value"? ' Don't think so.

      sub addOne { $_[0]+=1 } my $x = 1; addOne($x); print $x;

      It's the assignment to the lexical variables that makes the parameter passing look like "pass by value".

      2. "Class variables aren't standard"
      What do you mean by this?

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

      Edit by castaway: Closed small tag in signature

        "Pass by ' Don't think so.
        Yes, but what you're doing is explicitly accessing the argument list which is an array of aliases, which is somewhat of a hangover from earlier perls. But generally when you use the args passed into a subroutine you'll find that they were passed by value and not reference.
        What do you mean by this?
        In perl there's no standard way of creating or assigning class/object variables, whereas in PHP you can declare them with var $foo or create them with $this->foo = $thing and access them like so $this->foo.
        HTH

        _________
        broquaint

      Thank you for your Perl/PHP comparision chart! I just now learned how to read responses to my postings or I would have replied sooner. Again, Thanks!