<code><span><span><?php </span><span><span>interface</span><span>Code</span>{</span><span>//public $data=123; 错误 接口中不能有访问属性的数据</span><span>const</span> data =<span>123</span>;<span>//正确 接口中可以使用常量</span><span>public</span><span><span>function</span><span>_print</span><span>()</span>;</span><span>//public function _print2(){}; 错误,接口中不能用实现的方法</span> } <span><span>class</span><span>CPlusPlus</span><span>implements</span><span>Code</span>{</span><span>public</span><span><span>function</span><span>_print</span><span>()</span> {</span><span>echo</span><span>"std::cout <br>"</span>; } } <span><span>class</span><span>JavaScript</span><span>implements</span><span>Code</span>{</span><span>public</span><span><span>function</span><span>_print</span><span>()</span> {</span><span>echo</span><span>"console.log(...) <br>"</span>; } } <span>$C</span> = <span>new</span> CPlusPlus(); <span>$JS</span> = <span>new</span> JavaScript(); <span>$C</span>->_print(); <span>$JS</span>->_print(); <span>?></span></span></span></code>
以上就介绍了 PHP入门8 面向对象3 接口,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。