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

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

  • Comment on Re: Re: Re: php + Smarty looks like CGI

Replies are listed 'Best First'.
Re: Re: Re: Re: php + Smarty looks like CGI
by Jenda (Abbot) on May 18, 2003 at 16:33 UTC

    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

        Out of interest, how painless is it to override the accessors or mutators?

        1. Well ... but it's the aliases that are "passed" to the subroutine. When you do

        sub foo { my ($foo, $bar) = @_;
        you are assigning the values from the references/aliases passed to the subroutine to some lexical variables. The $foo and $bar are not the subroutine parameters, they are plain old lexicals that got their value from the parameters.

        2. I see. I've never worked with PHP so I did not know :-)

        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

Re: Re: Re: Re: php + Smarty looks like CGI
by Theo (Priest) on May 20, 2003 at 04:26 UTC
    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!