01-30-2008, 07:07 PM
|
#12 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by Alan @ CIT
Put an echo '' around 'you are old' and it should work fine
Alan
|
That's not the only syntactical problem, but the general structure of the Human class is ok.
Just for those people learning from this topic, the syntax errors include: - Class property declarations need 'var' (PHP4, supported in PHP5 = 'public'), 'public', 'private' or 'protected'.
PHP Code:
// Original
$fname;
$lname;
$mname;
$age;
// Fixed
private $fname;
private $lname;
private $mname;
private $age;
- Braces around variable names are generally reserved to being used inside double-quoted strings. If you're concatenating variables and strings, there's no need for them.
PHP Code:
// Original
echo "hello ".{$this->fname}." ".{$this->lname}." ".$this->mname;
// Fixed
echo 'Hello '.$this->fname.' '.$this->lname.' '.$this->mname;
Are you clear on what OOP is all about because no-one has really explained anything in this topic, yet. It's not quite as simple as wrapping functions up within a class!
|
|
|
|