PHP Manual Learning

Source: Internet
Author: User

Basic syntax

PHP tags, separators, annotations

When parsing a file, PHP looks for the start and end tags, that is , to separate the PHP code from the HTML;

Instruction delimiter: Like C or Perl, PHP needs to end the instruction with a semicolon after each statement.

Note: PHP supports c,c++ and Unix Shell-style (Perl-style) annotations.

 
  



Type

PHP supports 8 types of raw data.

Four types of scalar:

    • Boolen (Boolean): Specifies a Boolean value that uses the keyword TRUE or FALSE. Two are not case-sensitive.
    • Integer (integer type)
    • Float (floating-point, also called double)
    • String (String)

Two kinds of composite types:

    • Array (arrays)
    • Object (Objects)

Finally, there are two special types:

    • Resource (resources)
    • NULL (no type)

To ensure the readability of the Code, this manual also describes some pseudo-types:

    • Mixed (mixed type)
    • Number (numeric type)
    • Callback (callback type)

and the pseudo-variable $ ....

If you want to see the value and type of an expression, use the Var_dump () function; Use the GetType () function if you just want a readable type of expression for debugging purposes. To view a type, do not use GetType () and use the Is_type function. If you want to cast a variable to a type, you can use a cast or settype () function on it.

Variable

Variables in PHP are represented by a dollar sign followed by a variable name. Variable names are case-sensitive.

Constant

A constant is an identifier (first name) of a simple value. As the name implies, the value cannot be changed during script execution (except for the so-called magic constants, they are not constants). Changshime is considered to be case sensitive. Traditionally, constant identifiers are always capitalized.

 
  



Several "Magic constants" for PHP

name Description
__line__ The current line number in the file.
__file__ The full path and file name of the file. If used in the included file, returns the file name that is included. From PHP 4.0.2, __file__ always contains an absolute path (if it is a symbolic connection, the resolved absolute path), and the previous version sometimes contains a relative path.
__dir__ The directory where the file resides. If used in the included file, returns the directory where the included files are located. It is equivalent to DirName (__file__). Unless it is a root directory, the name in the directory does not include the trailing slash. (New in PHP 5.3.0) =
__function__ The name of the function (PHP 4.3.0 new addition). From PHP 5 This constant returns the name (case-sensitive) when the function is defined. In PHP 4, this value is always in lowercase letters.
__class__ The name of the class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters. The class name includes its declared action area (for example, Foo\bar). Note since PHP 5.4, __CLASS__ has also worked for trait. When used in the trait method, __class__ is the name of the class that invokes the trait method.
__trait__ Trait's name (PHP 5.4.0 new Plus). From PHP 5.4 This constant returns the name of the trait when it is defined (case-sensitive). The Trait name includes its declared function area (for example, Foo\bar).
__method__ The method name of the class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive).
__namespace__ The name of the current namespace (case-sensitive). This constant is defined at compile time (PHP 5.3.0 is new).

An expression

Operator

Process Control

Function

Classes and objects


Name space

The following code structure goes into the global namespace:

    • Functions (function)

    • Classes (Class)

    • Interfaces (interface)

    • Constants (constant, not class constant)

    • Variables defined outside of a function/method

Errors

Exception handling

Generator

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