PHP Coherent Interface

Source: Internet
Author: User
Introduction: This is a detailed page of PHP coherent interface, introduced and PHP, related knowledge, skills, experience, and some PHP source code and so on.

class= ' pingjiaf ' frameborder= ' 0 ' src= ' http://biancheng.dnbcw.info/pingjia.php?id=332955 ' scrolling= ' no ' > recent, See a lot of people are talking about coherent interface this thing, think about it, this is actually nothing, used early as JavaScript in the jquery, are already in use. It's just that PHP was recently flipped out and fired.

But it has to be said that the coherent interface also has its own advantages, that is, to make the code clearer, such as the Zend Select class inside, generate a SQL and execution is that intuitive:

$db = new zend_db (); This is written casually, mainly to show  $db->select ()->from ('     tablename ')     ->where (' id =? ', $id)     ->orwhere (' Name! =? ', $name);    Finally, you can call to generate this SQL  $sql = $db->__tostring ();


Since the PHP5, $a = new Object (); $b = $a; This $b directly into the address, rather than copy, such a coherent interface than the use of arrays to achieve efficiency is much higher, after all, the relative consumption of memory will be less? (estimated, not measured).



However, this thing really is like Ajax, belongs to the old bottle of new wine. The function in the previous class is to return a value, or true, and so on, and so on, is now the return $this; ), but overall, this is a good way to do it.

The coherent interface is simple and beautiful to write, but it has a tricky problem, and Ides like Zendstudio,eclipse don't seem to support automatic hints for coherent interfaces? In fact, the method of ending is also very simple, as long as the above code comment, follow the code comment specification of Phpdoc, after @return to indicate the type of object returned, these IDE also can implement automatic prompt.

More articles on "PHP Coherent Interface"

Love EE focus on Java Michael Jackson Video station JSON online tool

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.