我自己使用了以下代码,两者都给出了相同的结果.那么为什么我们使用类而不是普通函数,以及类和函数之间的区别是什么.
<?php
class MyClass{
public $property = "This is My Class Property";
public function getProperty(){
echo $this->property."<br />";
}
}
$obj=new MyClass();
echo $obj->getProperty();
?>
<?php
function getProp(){
$prop="This is My Class Property";
echo $prop;
}
getProp();
?>
Run Code Online (Sandbox Code Playgroud) php ×1