The difference between PHP language structure (Language constructs) and functions

Source: Internet
Author: User
I believe you often see a comparison of some PHP applications, said to replace strlen () with Isset (), isset than strlen execution speed and so on.

Example:

if (Isset ($username [5])) {

The username is at least six characters long.

}

The reason is that isset is a language structure, and strlen is a function. What is the language structure? Is it different from the function?

1. What are language structures and functions

Language structure: is the PHP language keywords, language grammar part; it can not be defined by the user or added to the language extension or library; it can have or can have no variables and return values.

Function: consists of blocks of code that can be reused.

2. Why language structure is faster than function

The reason is that in PHP, the function must first be decomposed into the language structure of the PHP parser, so there is this visible, the function is more than the language structure of a layer of parser parsing. This can be better understood as

What language structure is faster than a function.

3. Differences in language structure and functions

Language structure is faster than corresponding function function

Language structure in error processing is relatively robust, because it is a language keyword, so there is no re-processing links

The language structure cannot be disabled in configuration items (php.ini), and functions can.

The language structure cannot be used as a callback function

4. List of language structures

Echo ()

Print (), yes, it's a language structure

Die ()

Isset (): Only for variables

Unset ()

Include (), no include_once ()

Require (), no require_once ()

Array ()

List ()

Empty (): Only for variables


Isset () returns TRUE in the following cases:


$var = "";

$var = Array ();

$var = 0;

$var = false;

So far: Only NULL is assigned or not assigned, it is recommended to use empty

  • Related Article

    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.