一、自訂函數
<span>function</span> add(<span>$a</span>,<span>$b</span><span>){ </span><span>$c</span>=<span>$a</span>+<span>$b</span><span>; </span><span>echo</span> 'add test:'<span>; </span><span>echo</span><span>$c</span><span>; </span><span>return</span><span>$c</span><span>; } add(</span>1,2);
輸出結果:
add test:3
二、呼叫類別裡面函數
1、雙冒號::,不用實例化,直接類別名稱
1、雙冒號::,不用實例化,直接類別名稱
>,實例化後的物件使用
<span>class</span><span> test{ </span><span>public</span><span>function</span> add(<span>$a</span>,<span>$b</span><span>){ </span><span>$c</span>=<span>$a</span>+<span>$b</span><span>; </span><span>echo</span> 'class test:'<span>; </span><span>echo</span><span>$c</span><span>; </span><span>return</span><span>$c</span><span>; } } test</span>::add(1,2);
以上就介紹了PHP學習日記(一)-類別、函數的使用,包括了物件方面的內容,希望對PHP教程有興趣的朋友有所幫助。