Re: [PHP4BETA] Object Oriented Programming
| From: | Zeev Suraski | Date: | Wed, 29 Mar 2000 22:46:11 +0000 |
| Subject: | Re: [PHP4BETA] Object Oriented Programming | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-12843@lists.php.net to get a copy of this message | ||
Function arguments are always simple variables, as far as the function is concerned. That's true for both regular functions, and functions embedded inside classes (methods).
If you look at your function,
function Session($this->seshid,$this->userid=0){
// connect to MySQL etc
}
you can see that the arguments aren't simple variables, but rather, properties of $this (e.g. $this->seshid). This syntax means nothing to PHP, and it's invalid. You cannot give default values to object properties inside the function argument list; You can only give default values to the function arguments, which in turn, can only be simple variables.
Your function should be changed to look like this:
function Session($seshid,$userid=0){
// Use $seshid and $userid
...
// If you wish to initialize the object properties $this->seshid and $this->userid for
// future use in other methods:
$this->seshid = $seshid;
$this->userid = $userid;
}
Zeev
At 22:37 29/03/2000 , Louisiana Attorneys Network wrote:
I'm using PHP 4 and am trying to branch into Object oriented programming. I've copied examples from the Profesional Php Programming book. Problem is I keep getting an error when defining a function in a class. Here is an abbreviated form of the class Session {-- Zeev Suraski <zeev@zend.com> http://www.zend.com/// Define the properties:var $seshid; var $userid;// Define the methods:function Session($this->seshid,$this->userid=0){ // connect to MySQL etc }} I get a parse error that PHP is expecting a closing ')' even though there are the correct number of parenthesis on the line with function Session. It seems that it's not liking the "$this->" syntax. Does anyone know why? Thanks Scott xjab@fastband.com -- PHP 4.0 Beta Mailing List <http://www.php.net/version4/> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net For additional commands, e-mail: php4beta-help@lists.php.net To contact the list administrators, e-mail: php4beta-admin@lists.php.net