[英]error calling a php class function
我正在嘗試在外部php類文件中調用函數
control.php
require_once ('../vista/ViewEscola.php');
$a = new A();
$a->foo();
這是外部文件ViewEscola.php
class A
{
public function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}
它什么也沒做
誰能幫我?
代替echo
嘗試從函數return
並傳遞變量作為函數的參數。也不要使用$this
。如果沒有出現任何錯誤,請嘗試使用ini_set('display_errors', true'); error_reporting(E_ALL);
顯示錯誤ini_set('display_errors', true'); error_reporting(E_ALL);
ini_set('display_errors', true'); error_reporting(E_ALL);
嘗試像
require_once ('../vista/ViewEscola.php');
class A
{
public function foo($arg)
{
if (isset($this)) {
$ret = '$arg is defined (';
$ret .= get_class($arg);
$ret .= ")\n";
} else {
$ret = "\$arg is not defined.\n";
}
return $ret;
}
}
$arg = 'Hi';
$a = new A();
$ret = $a->foo($arg);
echo $ret;
<?php
class A
{
public function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}
$a = new A();
$a->foo();
?>
我嘗試將上述代碼段執行到php中,並打印出“ $ this is defined(A)”,因此可能存在與將類文件的路徑包含到您的代碼段中有關的問題
您可以使用以下代碼段識別錯誤
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.