home.php如何從包含的PHP類中調用方法?
<?php
include 'myClass.php';
$sampleClass=main;
$sampleClass->renderHtml();
?>
myClass.php
<?php
class main
{
public $var="apple";
public function renderHtml()
{
echo "This is $var";
return;
}
}
現在,當我這樣做,我收到一個錯誤,它說:
Fatal error: Call to a member function renderHtml() on a
non-object in C:\wamp\www\home.php on line 5
注意:未定義的變量:用C VAR:\ WAMP \ WWW \ myClass.php上線8 –
好吧,我已經更新了我的答案。 .. –
非常感謝你:) –