<?php namespace App\Sdks\Services; use App\Sdks\Library\CommonHelper; class test extends CommonHelper { public function index() { //不懂这里面的 static::getSharedConfig() 这个方法是调用的那个类? return static::getSharedConfig()->logic->edu_page->search_page_size; } }
钟毅2017-10-04 16:32:28
This is a static class that commhelper has itself and cannot be instantiated. Because this is an object generated in a static function that has been defined in COMMHELPER. Simply put, this function function returns the static function defined in the test parent class. Just think that the things that the parent class has will be there by default. Use it if you want. More convenient to use.
数据分析师2017-10-01 00:30:35
Confused about static in php? - PHP Chinese website Q&A - Confused about static in php? - PHP Chinese website Q&A
Take a look and learn.
阿神2017-02-24 09:24:19
首先,你应该先了解static的用法,再去理解你不明白的这段代码的含义。先给你看你一个static使用的例子:
class zhang{ protected static $name = 'zhangsan'; public static function getName() { echo static::$name; } } class li extends zhang { protected static $name = 'lisi'; } Sedan::getName();
上面输出的是结果是:lisi;也就是数据当前类的属性。
迷茫2017-02-24 09:23:31
如果本类没有的话,那就代表它的父类中的getSharedConfig()静态方法,这里也可以写成self::getSharedConfig(),父类就是extends 的那个类哈
class father { static public function fatherF(){ echo "我在父类中哦"; } }class oneself extends father{ public function start(){ // return self::fatherF(); return static::fatherF(); // return self::oneselfF(); } static public function oneselfF(){ echo "我在儿子类中哦"; } }echo PHP_VERSION; // 版本$c = new oneself;$c->start();/* +---------------------------------------------------------------------- | 5.6.29 我在父类中哦 +---------------------------------------------------------------------- */