我想學習面向對象和類和所有那些在PHP中的好東西,我終於學習了使用它的一些好的sytax,我很好奇如果有開始一個新的對象而不是使用靜態方法的好處......讓我告訴了我的意思了一些代碼...更好地使用PHP中的對象或靜態函數?
<?PHP
test class
{
public function cool()
{
retunr true;
}
}
//Then calling it like this
$test = new test();
$test->cool();
?>
OR
<?PHP
test class
{
public static function cool()
{
retunr true;
}
}
//Then calling it like this
test::cool();
?>
我意識到這是最基礎的例子想象得到的回答可能視情況而定,但也許你可以幫助我更好地理解一下
似乎是一個偉大的經驗法則,特別是關於代碼的可測試性。 – svandragt