在PHP中,我该怎么做:
$test = array(1,2,3,4);
$i=0;
While (!empty($test)) {
//do something with $test[i];
//remove $test[$i];
unset($test[$i]);
}
Run Code Online (Sandbox Code Playgroud)
谢谢
[注意:在cfcs中包含代码通常是不好的做法,(请参阅下面的答案),所以请考虑这只是研究]
总而言之,我有一个类和一个子类以及一个被子类覆盖的方法.当我在子类中对方法进行硬编码时,一切正常,当我使用cfinclude将它包含在伪构造函数中时,mixin样式,我得到一个"例程不能多次声明".错误.
这看起来非常简单.我想念的是什么:这个混合?
父类:
<cfcomponent >
<cffunction name="hola" hint="i am the parent method">
<cfreturn "hola - parent">
</cffunction>
</cfcomponent>
Run Code Online (Sandbox Code Playgroud)
儿童班:
<cfcomponent extends="mixinTestParent">
<!--- this would work, successfully overridding parent method
<cffunction name="hola" hint="i am the child method">
<cfreturn "hola - child">
</cffunction>--->
<cfinclude template="mixinTestInc.cfm">
<cffunction name="init" access="public" returntype="any" output="false">
<cfreturn this>
</cffunction>
</cfcomponent>
Run Code Online (Sandbox Code Playgroud)
包括:
<cffunction name="hola" hint="i am the child method" access="public">
<cfreturn "hola - child">
</cffunction>
Run Code Online (Sandbox Code Playgroud)
亚军:
<cfset test = new mixinTestChild().init()>
<cfdump var="#test.hola()#">
Run Code Online (Sandbox Code Playgroud)
提前致谢!!