What is the need for a PHP namespace and a standalone template engine?

Source: Internet
Author: User
PHP introduced a namespace with the "\" Partition of the syntax, is original, very unaccustomed, and, with well-designed catalog results to manage the class, but also to achieve the management of the namespace, I think the new introduction of namespace,used and so is the lily, hope to teach exchange.

Besides the template engine, I think the only use of the template engine is to separate the writing interface (template) from the writing business logic so that the artist can independently develop the template to reduce the workload of the programmer. But for art, learning similar to the {var} template tag, as much as writing PHP code directly fill the template difficult, and non-PHP syntax template requires the process of template compilation, consumption performance. In addition, I would like to ask the advantages of various template engines where?

Please do not simply answer: "Your project is not large enough, there are not enough parallel developers"

Reply content:

PHP introduced a namespace with the "\" Partition of the syntax, is original, very unaccustomed, and, with well-designed catalog results to manage the class, but also to achieve the management of the namespace, I think the new introduction of namespace,used and so is the lily, hope to teach exchange.

Besides the template engine, I think the only use of the template engine is to separate the writing interface (template) from the writing business logic so that the artist can independently develop the template to reduce the workload of the programmer. But for art, learning similar to the {var} template tag, as much as writing PHP code directly fill the template difficult, and non-PHP syntax template requires the process of template compilation, consumption performance. In addition, I would like to ask the advantages of various template engines where?

Please do not simply answer: "Your project is not large enough, there are not enough parallel developers"

Namespaces are not used much, skip, just say the template engine.

The use of the template engine, in fact, is back to the original requirements: nothing more than the desire to output HTML as easily as possible.

Although PHP is different from many other languages, it was originally designed to make it easier to implement some dynamic features in a bunch of HTML (so there are many projects that actually use PHP to implement the template, such as WordPress is a bunch of PHP) But compared to the smarty (such as the template engine), in the direct writing of HTML, it is true that most of the time is still smarty more convenient, because the Smarty engine is specifically optimized for writing HTML. For example, in smarty, you need to have a variable HTML escaped:

{$xxx|escape:'html'}

What about PHP?


  
   

If you change to a quotation mark escape, smarty only need to change HTML to quotes on the line, formally maintained the same, in writing and reading are more comfortable. As for PHP, of course, htmlspecialchars change to addslashes also can, but PHP function, really difficult to use (and difficult to remember and difficult to write, many similar to a set of functions, the order of variables are not uniform convention, who use who nausea) ... On this point I have deep experience, 10 when I wrote a project, I think it is not very necessary to use smarty, so I use PHP to achieve, write very painful, if at that time to Smarty know a little more (just heard, feel as if compared to the weight level is useless), it is absolutely impossible to appear this situation.

Recently webpy used more, webpy of the template engine I think more than the smarty to use a bit more fun in HTML escape: It is escaped by default, you need to refer to the variable in the page, directly on the $xxx line. It's also simple if you don't need to escape: $:xxx .

These features, specifically optimized for HTML development, are really much better for PHP, which is a very casual, random, and randomly-stacked language in the first place.

And on the issue of compilation, efficiency: In fact, most of the template engine is compiled cache, but only when the first access to compile, and then the cost is almost negligible. About the efficiency of the problem, in fact, can also spit trough a php--originally inefficient, this cost really nothing. (P.S. I'm fast becoming PHP black)

Use and so on is the core function of the namespace ah, obviously, this is from the C + + and other language reference.

Namespaces are designed to enhance the management of identifiers, and not all cases use a very long, fully qualified name, so there is a mechanism for using the identifier to abbreviate the namespace portion of the identifiers.

Of course, the PHP namespace does not really do a good design, such as a wonderful backslash, the function and variable function is limited, and so on.

  • 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.