Short tag: , you need to open the short_open_tag command of the php.ini file ASP style tag: <% %>, you need to open the asp_tags directive of the php.ini file php data types (9 types) Four scalar types boolean integ"/> Short tag: , you need to open the short_open_tag command of the php.ini file ASP style tag: <% %>, you need to open the asp_tags directive of the php.ini file php data types (9 types) Four scalar types boolean integ">

Home  >  Article  >  Backend Development  >  What beginners should know about PHP

What beginners should know about PHP

零下一度
零下一度Original
2017-06-23 13:35:501091browse

Start and end tags

  1. Two commonly used ones: ,

  2. ##Short tag:

    , you need to open the short_open_tag command of the php.ini file

  3. ASP style tag:

    <% %>, you need to open the asp_tags directive of the php.ini file

  4. ##php data type (9 Kinds)

    Four scalar types
##boolean
  • integer
  • float
  • string
Three composite types
array
  • object
  • callable
Two special types
  1. ##resource
  • NULL (no type)

  • Pseudo-type
  1. mixed )
  • number (number type)

  • callback (callback type, also called callable)

  • array|object

  • void

  • ##pseudovariable$...
  1. Type detection function (is_type), eg:

    is_string($str)

  2. ##Super global variable

  3. $GLOBALS

    $_SERVER: Save information about headers, paths, script locations, etc.
  • ##$_REQUEST: Collect data submitted by html forms
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
  • Access global variables within the function body
  • global $variable_name

$GLOBALS[variable_name]
  • Set constants
  • define(const_name, const_value, boolean)

const_name: constant name

const_value: constant value
  • boolean: constant names are case-sensitive, default false is sensitive, true is insensitive
  • Create array
  • array()

  • Get the array length

    count($arr)

  • Array sorting : ascending order

    sort(), descending order rsort()

  • Array key sorting: ascending order ksort(), descending order krsort()

  • Array value sorting: ascending asort(), descending arsort()

  • foreach loop (only for arrays)

  • foreach($array as $value) {}

  • foreach($array as $key => $value) {}

  • Magic variable

  • __LINE__
: Current line number

  • __FILE__: Full path and file name of the file

  • __DIR__: The directory where the file is located

  • __FUNCTION__: Function name

  • __METHOD__: The method name of the class

  • __NAMESPACE__: The name of the current namespace

  • Object-oriented

    Classes are defined using the class keyword followed by the class name

Variables and variables can be defined within a pair of braces ({}) after the class name Method
  • Variables of the class are declared using var. Variables can also be initialized with values.
  • Function definition is similar to the definition of the PHP function, but can only be passed This class and its instantiated objects access
  • Constructor
  • function __construct($arg1, $arg2, ...)
  • , mainly used to initialize objects

  • Destructor

    function __destruct(), called at the end of the object’s life cycle, can destroy variables

  • Inheritance

    extends, PHP does not support multiple inheritance

  • Method rewriting, subclasses can rewrite parent class methods to meet needs

    Yes Access control of properties or methods:
  • public
  • ,

    protected

    ,
  • private
  • Interfaceinterface

  • Constants are defined with

    const, no need for $

  • ##Abstract class
  • Attributes or methods declared as static can be accessed directly without instantiating the class

  • The parent class method is declared final and cannot be overridden or inherited by subclasses

  • Subclass calls parent class constructor method

    parent::__construct()

The above is the detailed content of What beginners should know about PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn