Home >Backend Development >PHP Tutorial >Getting Started with PHP 8 Object Oriented 3 Interface
<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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
The above introduces the PHP Getting Started 8 Object-Oriented 3 interface, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.