相同的命名空间找不到 class 的构造函数
Same namespace cannot find constructor of class
我正在尝试实例化 class A 的对象,该对象与我当前的 class C 具有相同的命名空间,但我失败了。
两个 class 都在命名空间 App\Models.
中
这是A.php的代码:
namespace App\Models;
class A implements B
{
private $url;
public function __construct($url = "")
{
$this->url = $url;
}
}
这是C.php的代码:
namespace App\Models;
require_once 'A.php';
class C
{
private $url;
...some functions...
public function getC()
{
$test = A($this->url);
return $test;
}
...other functions
}
我明白了
Error: Call to undefined function App\Models\A()
在 phpunit 中,我无法理解我做错了什么。
我正在使用 PHP 7.0.24
通过调用 A()
,您将调用 A()
作为函数。看起来你忘记了 new
:
class C
{
private $url;
...some functions...
public function getC()
{
$test = new A($this->url);
return $test;
}
...other functions
}
您犯了一个简单的错字 - 我们中最优秀的人都会遇到这种情况。
我正在尝试实例化 class A 的对象,该对象与我当前的 class C 具有相同的命名空间,但我失败了。
两个 class 都在命名空间 App\Models.
中这是A.php的代码:
namespace App\Models;
class A implements B
{
private $url;
public function __construct($url = "")
{
$this->url = $url;
}
}
这是C.php的代码:
namespace App\Models;
require_once 'A.php';
class C
{
private $url;
...some functions...
public function getC()
{
$test = A($this->url);
return $test;
}
...other functions
}
我明白了
Error: Call to undefined function App\Models\A()
在 phpunit 中,我无法理解我做错了什么。
我正在使用 PHP 7.0.24
通过调用 A()
,您将调用 A()
作为函数。看起来你忘记了 new
:
class C
{
private $url;
...some functions...
public function getC()
{
$test = new A($this->url);
return $test;
}
...other functions
}
您犯了一个简单的错字 - 我们中最优秀的人都会遇到这种情况。