php语法非常类似c++;
一段简单的面向对象代码 :
catname = $name;
$this->catcolor = $color;
$this->catage = $age;
}
//打印出所有信息
function showcat()
{
// \n表示空格
return {$this->catname}\n.{$this->catcolor}\n.{$this->catage};
}
}
$smallcat = new cat(lex,black,3);
//给对象没有的属性赋值,php是不会报错的;
$smallcat ->wrong = error;
print {$smallcat->showcat()};
?>
print 用于输出所有的项;
php中“”和‘’没有任何区别;
php中的方法默认为public 类型;属性默认为private类型
php中如果符合语法规范,那么它将不会报错,所以php检查错误是一件非常麻烦的事;
以上就介绍了php学习日记1 ----面向对象基础,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。