<?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;
}
}Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个是commhelper自己就有的静态类,不能实例化的。因为这个是在COMMHELPER中就已经定义了是静态函数中生成的对像。简单地说就是这个功能函数,返回test父类中定义的静态函数。就想当父类就带有的东西默认就有。想用就用。更方便使用。
php中的 static 疑惑?-PHP中文网问答-php中的 static 疑惑?-PHP中文网问答
围观一下哦,学习一下。
首先,你应该先了解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;也就是数据当前类的属性。
如果本类没有的话,那就代表它的父类中的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 我在父类中哦 +---------------------------------------------------------------------- */