Home >Backend Development >PHP Tutorial >Getting Started with PHP 8 Object Oriented 3 Interface

Getting Started with PHP 8 Object Oriented 3 Interface

WBOY
WBOYOriginal
2016-07-28 08:26:211082browse

Keyword interface


The interface cannot have implemented methods


Cannot use data, but can have constants


JAVA interface: http://blog.csdn.net/a289672082/article/details/51518398
<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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP encryption technologyNext article:PHP encryption technology