1、封装性:
将方法和属性封装到类中,将具体的实现隐藏到类中,只提供一些开放的方法去访问,可以通过权限控制来实现。
<?php
class person{
private name = 'user';
private age = 11;
private intro = '';
private function setIntro(){
$this->intro = $this->name.'的年龄是'.$this->age.'岁';
}
//获取介绍信息
public function getIntro(){
$this->setIntro;
return $this->intro;
}
}
二、继承性
子类继承父类的属性和方法,不需要重新编写定义,达到代码重用的效果
三、多态性
相同的函数或方法作用于不同对象产生不同的结果。
<?php
class foo {
function bar($username) {
echo $username."is an athlete";
}
}
class foo1 {
function bar($username) {
echo $username." is an entrepreneur";
}
}
// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("machel"));
$foo = new foo1;
call_user_func_array(array($foo, "bar"), array("machel"));