PHP coherent interface

Source: Internet
Author: User

Brief Introduction: This is a detailed page of PHP coherent interfaces. It introduces related knowledge, skills, experiences, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 332955 'rolling = 'no'>
Recently, many people have been discussing the coherent interface and think about it carefully. It is actually nothing. jquery in Javascript has been used for a long time. It's just that PHP has been turned over recently.

But what I have to say is that a coherent interface also has its own advantages, that is, it can makeCodeFor example, in the Select class of Zend, it is as intuitive to generate an SQL statement and execute it:

 
$ Db = new zend_db (); // This is a random write, mainly to show $ db-> select ()-> from ('tablename ') -> where ('Id =? ', $ Id)-> orwhere ('name! =? ', $ Name); // you can call this SQL statement to generate $ SQL = $ db->__ tostring ();

Since PhP5, $ A = new object (); $ B = $ A; this $ B is directly converted into an access address instead of a copy, such a coherent interface is much more efficient than using Arrays for implementation. After all, the memory usage will be less? (Estimated, not tested ).

However, this is indeed the same as Ajax, and it belongs to the old bottled new wine. In the past, the function in the class returned a value, true, and so on. Now it is return $ this; directly returning itself (I don't know whether the efficiency is improved or decreased .), But in general, this is a good method.

The coherent interface is very simple. It is also very beautiful to write, but it encountered a difficult problem. Ide like zendstudio and eclipse does not seem to support automatic prompts of coherent interfaces? In fact, the ending method is also very simple. As long as the above code annotation follows the phpdoc code annotation specification and specifies the type of returned object after @ return, these ides can also implement automatic prompts.

More articles on "php coherent interfaces"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/332955.html pageno: 11.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.