惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 最新话题
Help Net Security
Help Net Security
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
S
SegmentFault 最新的问题
J
Java Code Geeks
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
博客园_首页
H
Hacker News: Front Page
T
Threatpost
Jina AI
Jina AI
博客园 - Franky
月光博客
月光博客
L
LINUX DO - 热门话题
The Cloudflare Blog
H
Heimdal Security Blog
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
S
Secure Thoughts
T
Tenable Blog
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 老男孩玩编程

php中的反引号 十四条令PHP初学者头疼问题大总结 免费开源微博程序大全——免费开源微博对比解析 JavaScript窗口与提示大全 大型网站,我建议要考虑的问题: 制作精美圆角表格两种方法 关于GridView中自定义分页、单选、多选的简单应用 SQL精华 ASP.NET编程中的十大技巧 SQL SERVER临时表的使用 有效编写软件的75条建议 IT从业人员必看的10个论坛 程序员每天该做的事 动态生成button并关联其onclick事件 使用C#从数据库读取图像二进制流的代码 在ASP.NET 中实现单点登录 简单的数据连接方法 ASP.NET程序中常用的三十三种代码 SQL语法全集
PHP双冒号::的用法
老男孩玩编程 · 2013-01-06 · via 博客园 - 老男孩玩编程

PHP双冒号::的用法

2010-09-05

双冒号操作符即作用域限定操作符Scope Resolution Operator可以访问静态、const和类中重写的属性与方法。

在类定义外使用的话,使用类名调用。在PHP 5.3.0,可以使用变量代替类名。

Program List:用变量在类定义外部访问

04     const CONST_VALUE = 'Fruit Color';
08 echo $classname::CONST_VALUE; // As of PHP 5.3.0
10 echo Fruit::CONST_VALUE;

Program List:在类定义外部使用::

04     const CONST_VALUE = 'Fruit Color';
07 class Apple extends Fruit
09     public static $color = 'Red';
11     public static function doubleColon() {
12         echo parent::CONST_VALUE . "\n";
13         echo self::$color . "\n";

程序运行结果:

Program List:调用parent方法

05     protected function showColor() {
06         echo "Fruit::showColor()\n";
10 class Apple extends Fruit
12     // Override parent's definition
13     public function showColor()
15         // But still call the parent function
16         parent::showColor();
17         echo "Apple::showColor()\n";

程序运行结果:

Program List:使用作用域限定符

05         public function showColor()
07             return $this->color;
13         public $color;
15         public function __construct()
17             $this->color = "Banana is yellow";
20         public function GetColor()
22             return Apple::showColor();
26     $banana = new Banana;
27     echo $banana->GetColor();

程序运行结果:

Program List:调用基类的方法

06     static function color()
08         return "color";
11     static function showColor()
13         echo "show " . self::color();
17 class Apple extends Fruit
19     static function color()
26 // output is "show color"!

程序运行结果: