<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></code>
위의 내용은 PHP 시작하기 8 객체 지향 3 인터페이스를 소개하며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.