PHP 中使用变量类名来动态调用类静态方法

<p>话不多说,直接看代码:</p><p>PHP</p><pre class="brush:php;toolbar:false">&lt;?php classcls { publicstaticfunctiontest($userName) { echo&#39;Hi,&#39;.$userName.&quot;\n&quot;; } } $className=&#39;cls&#39;; $className::test(&#39;Tom&#39;);//PHP&gt;=5.3.0 call_user_func(array($className,&#39;test&#39;),&#39;Jack&#39;);//PHP3&gt;=3.0.3,PHP4,PHP5 call_user_func_array(array($className,&#39;test&#39;),array(&#39;Lily&#39;));//PHP4&gt;=4.0.4,PHP5 ?&gt;</pre><pre class="brush:php;toolbar:false">&lt;?php classcls { publicstaticfunctiontest($userName) { echo&#39;Hi,&#39;.$userName.&quot;\n&quot;; } } $className=&#39;cls&#39;; $className::test(&#39;Tom&#39;);//PHP&gt;=5.3.0 call_user_func(array($className,&#39;test&#39;),&#39;Jack&#39;);//PHP3&gt;=3.0.3,PHP4,PHP5 call_user_func_array(array($className,&#39;test&#39;),array(&#39;Lily&#39;));//PHP4&gt;=4.0.4,PHP5 ?&gt;</pre>
RangeTime:0.007374s
RangeMem:204.52 KB
返回顶部 留言