为类类型参数传递null会导致捕获错误?!? [英] Passing null for a class-typed argument renders catchable error ?!?

查看:167
本文介绍了为类类型参数传递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?


这篇关于为类类型参数传递null会导致捕获错误?!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆