PHP static

Jul 29, 2016 am 09:02 AM
sta static type val

static belongs to the class itself and is common to instantiated objects.

Usage form:

static $val;
static function func(){}

Calling form:

Class name: :$val;
Class name: :func();

<code><span><span><?php </span><span><span>class</span><span>sta</span>{</span><span>public</span><span>$temp</span> = <span>123</span>;
    <span>static</span><span>$type</span> = <span>100</span>;
    <span>static</span><span><span>function</span><span>stat</span><span>()</span>{</span><span>$me</span> = <span>new</span><span>self</span>;
        <span>//静态方法中不能使用this关键字</span><span>echo</span><span>'common val:'</span>.<span>$me</span>->temp.<span>""</span>;
        <span>echo</span><span>'static val:'</span>.sta::<span>$type</span>.<span>"<hr>"</span>;
        <span>echo</span><span>'static val:'</span>.<span>$me</span>::<span>$type</span>.<span>"<hr>"</span>;
        <span>//静态方法中亦不可调用普通方法</span>
    }
}

<span>echo</span><span>'sta:'</span>.sta::<span>$type</span>.<span>""</span>;
<span>echo</span> sta::stat();

<span>$a</span> = <span>new</span> sta();
<span>echo</span><span>'a:'</span>.<span>$a</span>::<span>$type</span>.<span>""</span>;

<span>$b</span> = <span>new</span> sta();
<span>$a</span>::<span>$type</span> = <span>200</span>;
<span>echo</span><span>'b:'</span>.<span>$b</span>::<span>$type</span>.<span>""</span>;</span></span></code>
Copy after login

PHP static

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced static in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does sta mean? What does sta mean? Sep 07, 2023 pm 04:44 PM

STA has different meanings in different fields, namely: 1. In Wi-Fi networks, STA represents terminal equipment or client equipment; 2. In the IEEE 802.11 standard, STA refers to terminal equipment in wireless networks; 3. In the tourism industry, STA stands for short-term accommodation; 4. In schools, STA stands for student examination administration; 5. In statistics, STA stands for statistical analysis. STA as an abbreviation may have other meanings in different fields, and the specific meaning should be interpreted according to the context and the background of the specific field.

Solve Ubuntu mounting mobile hard disk error: unknown file system type exfat Solve Ubuntu mounting mobile hard disk error: unknown file system type exfat Jan 05, 2024 pm 01:18 PM

An error occurs when ubuntu mounts a mobile hard disk: mount: unknownfilesystemtype'exfat'. The processing method is as follows: Ubuntu13.10 or install exfat-fuse: sudoapt-getinstallexfat-fuseUbuntu13.04 or below sudoapt-add-repositoryppa:relan/exfatsudoapt-getupdatesudoapt-getinstallfuse- exfatCentOS Linux mount exfat format USB disk error solution to load extfa in CentOS

What are the uses of the Type keyword in Go? What are the uses of the Type keyword in Go? Sep 06, 2023 am 09:58 AM

The usage of the Type keyword in Go includes defining new type aliases or creating new structure types. Detailed introduction: 1. Type alias. Use the "type" keyword to create an alias for an existing type. This alias does not create a new type, but only provides a new name for the existing type. Type aliases can improve code. The readability of the code makes the code clearer; 2. Structure type. Use the "type" keyword to create a new structure type. The structure is a composite type that can be used to define custom types containing multiple fields. etc.

What is the function and usage of static in C language What is the function and usage of static in C language Jan 31, 2024 pm 01:59 PM

The role and usage of static in C language: 1. Variable scope; 2. Life cycle; 3. Internal function; 4. Modify global variables; 5. Modify function; 6. Other uses; Detailed introduction: 1. Variable scope, when If there is the static keyword before a variable, then the scope of the variable is limited to the file in which it is declared. In other words, the variable is a "file-level scope", which is very useful for preventing the "duplicate definition" problem of variables; 2. Life cycle, static variables are initialized once when the program starts executing, and destroyed when the program ends, etc.

Linux type command Linux type command Mar 20, 2024 pm 05:06 PM

In this guide, we will learn more about the &quot;type&quot; command in Linux. Prerequisites: To perform the steps demonstrated in this guide, you need the following components: A properly configured Linux system. See how to create a LinuxVM for testing and learning purposes. Basic understanding of the command line interface The Type command in Linux is different from other Linux-specific commands (for example: ls, chmod, shutdown, vi, grep, pwd, etc.). The &quot;type&quot; command is a built-in Bash function that is displayed as an argument. Information about the command type provided. $type In addition to Bash, other shells (Zsh, Ksh, etc.) also come with

Practical application scenarios and usage skills of the static keyword in C language Practical application scenarios and usage skills of the static keyword in C language Feb 21, 2024 pm 07:21 PM

Practical application scenarios and usage skills of the static keyword in C language 1. Overview static is a keyword in C language, used to modify variables and functions. Its function is to change its life cycle and visibility during program running, making variables and functions static. This article will introduce the actual application scenarios and usage techniques of the static keyword, and illustrate it through specific code examples. 2. Static variables extend the life cycle of variables. Using the static keyword to modify local variables can extend their life cycle.

How to use static, this, super, and final in Java How to use static, this, super, and final in Java Apr 18, 2023 pm 03:40 PM

1. static Please look at the following program first: publicclassHello{publicstaticvoidmain(String[]args){//(1)System.out.println("Hello, world!");//(2)}} Have seen this Segment programs are familiar to most people who have studied Java. Even if you have not learned Java but have learned other high-level languages, such as C, you should be able to understand the meaning of this code. It simply outputs "Hello, world" and has no other use. However, it shows the main purpose of the static keyword.

How to use Java modifiers abstract, static and final How to use Java modifiers abstract, static and final Apr 26, 2023 am 09:46 AM

Modifier abstract (abstract) 1. Abstract can modify a class (1) The class modified by abstract is called an abstract class (2) Syntax: abstractclass class name {} (3) Features: Abstract classes cannot create objects separately, but they can be declared Reference the abstract class name reference name; (4) Abstract classes can define member variables and member methods (5) Abstract classes have constructors. When used to create subclass objects, jvm creates a parent class object by default; abstract constructor methods apply Applied when jvm creates parent class object. 2. Abstract can modify methods (1) The method modified by asbtract is called an abstract method (2) Syntax: access modifier abstract return value

See all articles