为类类型参数传递null会导致捕获错误?!?

为类类型参数传递null会导致捕获错误?!?

问题描述:

我有一个方法

I have a method


>>>
>>>



function appendChildNode(AST $ aNewChild){

...

}

<<<


其中AST是一个类。如果我传递null,PHP会呈现以下消息:

function appendChildNode( AST $aNewChild ) {
...
}
<<<

where AST is a class. If I pass null, PHP renders this message:


>>>
>>>



可捕获的致命错误:参数1传递给AST :: appendChildNode()

必须是一个实例AST,null给出,调用/ Applications / MAMP /

htdocs / compile / includes / CParser.inc.php(517):eval()'代码在第1行

并在/Applications/MAMP/htdocs/compile/includes/AST.inc.php中定义
第43行


<<<


任何想法,为什么我都不能传递空值?


[appendChildNode()是在类AST中声明的方法] br />

Catchable fatal error: Argument 1 passed to AST::appendChildNode()
must be an instance of AST, null given, called in /Applications/MAMP/
htdocs/compile/includes/CParser.inc.php(517) : eval()''d code on line 1
and defined in /Applications/MAMP/htdocs/compile/includes/AST.inc.php
on line 43
<<<

Any ideas, why I can''t pass a null value?

[appendChildNode() is a method declared inside the class AST]

aNewChild){

...

}

<<


其中AST是一个类。如果我传递null,PHP会呈现以下消息:
aNewChild ) {
...
}
<<<

where AST is a class. If I pass null, PHP renders this message:

>>>
>>>



可捕获的致命错误:参数1传递给AST :: appendChildNode()

必须是一个实例AST,null给出,调用/ Applications / MAMP /

htdocs / compile / includes / CParser.inc.php(517):eval()'代码在第1行

并在/Applications/MAMP/htdocs/compile/includes/AST.inc.php中定义
第43行


<<<


任何想法,为什么我都不能传递空值?


[appendChildNode()是在类AST中声明的方法] php中的

Catchable fatal error: Argument 1 passed to AST::appendChildNode()
must be an instance of AST, null given, called in /Applications/MAMP/
htdocs/compile/includes/CParser.inc.php(517) : eval()''d code on line 1
and defined in /Applications/MAMP/htdocs/compile/includes/AST.inc.php
on line 43
<<<

Any ideas, why I can''t pass a null value?

[appendChildNode() is a method declared inside the class AST]


,null不仅是一个值而且是一个类型,并且类型提示是违反



in php, null is not only a value but also a type, and the type hint was
violated


1月13日,03:56,Peter Pei < yan ... @ telus.comwrote:
On 13 Jan., 03:56, "Peter Pei" <yan...@telus.comwrote:
php中的
,null不仅是一个值而且是一个类型,类型提示是

违反
in php, null is not only a value but also a type, and the type hint was
violated



好​​的,thx。如何将空指针作为对象传递?

OK, thx. How do I have to pass a null ''pointer'' as an object?