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

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: php + Smarty looks like CGI
by broquaint (Abbot) on May 18, 2003 at 17:26 UTC
    "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?
        If you've got a recent enough version (as is usually the case with PHP) you can do it very easily indeed by creating __get and __set methods and the calling then overload function with appropriate class name.
        HTH

        _________
        broquaint

      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