PHP重载=运算符 [英] php overload = operator
问题描述
可能重复:
PHP中的运算符重载
是否可以重载=运算符?
所以我想成为以下人:
class b{
function overloadis(){
// do somethng
}
}
$a = new b();
$a = 'c';
在上面的示例中,当$ a ='c'时,我希望这样做;调用时,首先调用重载方法,然后该函数确定是否执行了该操作(将$ c赋给$ a)或被中止.
可以这样做吗?
提前Thnx, 鲍勃
否. PHP不支持运算符重载,但有一些例外情况(如@NikiC所述:"PHP支持某些运算符的重载,例如[],->和(字符串),还允许重载某些语言结构(如foreach)". /p>
Possible Duplicate:
Operator Overloading in PHP
Is there a way to overload the = operator ?
So want I is the following:
class b{
function overloadis(){
// do somethng
}
}
$a = new b();
$a = 'c';
In the example above, I want that when $a = 'c'; is called, the method overloadis is called first and then that function desides if the action (assign 'c' to $a) is executed or aborted.
Is it possible to do this ?
Thnx in advance, Bob
No. PHP doesn't support operator overloading, with a few exceptions (as noted by @NikiC: "PHP supports overloading of some operators, like [], -> and (string) and also allows overloading some language constructs like foreach").
这篇关于PHP重载=运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!