【发布时间】:2021-04-16 13:11:24
【问题描述】:
我有 3 个 .php 文件:some_class.php、some2_class.php 和 index.php
some_class.php
<?php
namespace Path\To;
class Some {
public $id;
public function __construct() {
$this -> id = 2021;
}
}
some2_class.php
<?php
class Some2 {
public function send(\Path\To $some)
{
}
}
index.php
require_once('some_class.php');
require_once('some2_class.php');
$c = new Path\To\Some();
$c2 = new Some2();
$c2 -> send($c);
当执行 index.php 时,我看到了:
致命错误:未捕获的类型错误:参数 1 传递给 Some2::send() 必须是 Path\To 的实例,Path\To\Some 的实例给定,称为 在第 8 行的 /home/l/liketeks/work/public_html/index.php 中并定义 在 /home/l/liketeks/work/public_html/some2_class.php:3 堆栈跟踪:#0 /home/l/liketeks/work/public_html/index.php(8): Some2->send(Object(Path\To\Some)) #1 {main} 抛出 /home/l/liketeks/work/public_html/some2_class.php 在第 3 行
【问题讨论】:
-
您对此有何疑问?为什么不修复该消息告诉您的内容?
标签: php