Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial OOP中->与::操作符的区别

OOP中->与::操作符的区别

Jun 23, 2016 pm 01:52 PM
gt oop the difference Operator

OOP中->与::操作符的区别有哪些?度娘不给力,找不到


回复讨论(解决方案)

static关键字修饰的变量,外部调用只能是::
static关键字修饰的方法,外部调用->和::皆可,习惯上用::,静态方法不能操作非静态变量
暂时想到就这些,楼下补充

->是实例调用
::是类中静态方法和静态属性的引用方法


-> 表示对象的成员
:: 作用域分辨运算符。手册中说:在没有声明任何实例的情况下访问类中的函数或者基类中的函数和变量很有用处。而 :: 运算符即用于此情况。
虽然 php 5.3 以后对 :: 的用法做了点限制,但总体并没有太大出入

1.如果function被定义成static 那么访问的时候,直接类名::方法名,静态属性同理。
2.如果只是定义function 方法名(),那么访问的时候,需要实例化类,$p = new xx(); $p->方法名();

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 Article Tags

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)

Does Bitcoin have stocks? Does Bitcoin have equity? Does Bitcoin have stocks? Does Bitcoin have equity? Mar 03, 2025 pm 06:42 PM

Does Bitcoin have stocks? Does Bitcoin have equity?

deepseek What is the difference between r1 and v3 version deepseek What is the difference between r1 and v3 version Feb 19, 2025 pm 03:24 PM

deepseek What is the difference between r1 and v3 version

Summary of FAQs for DeepSeek usage Summary of FAQs for DeepSeek usage Feb 19, 2025 pm 03:45 PM

Summary of FAQs for DeepSeek usage

What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading Mar 03, 2025 pm 11:54 PM

What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading

Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Mar 04, 2025 pm 04:06 PM

Why is Bittensor said to be the 'bitcoin' in the AI ​​track?

Is there any difference between South Korean Bitcoin and domestic Bitcoin? Is there any difference between South Korean Bitcoin and domestic Bitcoin? Mar 05, 2025 pm 06:51 PM

Is there any difference between South Korean Bitcoin and domestic Bitcoin?

Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025? Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025? Mar 03, 2025 pm 07:09 PM

Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025?

Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy Mar 04, 2025 am 10:21 AM

Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy

See all articles