从 PHP 匿名函数访问变量 [英] Accessing the variables from a PHP Anonymous Function

查看:36
本文介绍了从 PHP 匿名函数访问变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下带有静态变量的类.如何从匿名 PHP 函数中访问类的静态函数?

I have the following class with static variables. How can I access the static functions of a class from within an anonymous PHP function?

class MyClass {
  public static function MyFunction(mylocalparam){
      MyStaticClass:MyStaticMethod(function(myparam) use(mylocalparam){
         MyClass::MyFunction2(mylocalparam);
   });
  }

  private static function MyFunction2(someobject){
  }
}

我无法从匿名类中访问函数MyFunction2".你能就如何纠正这个问题提出建议吗?

I am having trouble accessing the function "MyFunction2" from within the anonymous class. Could you please advice on how to rectify this?

推荐答案

不会发生.您需要使静态函数public.匿名函数不在 MyClass 的范围内运行,因此无法访问其中包含的 private 方法.

Not going to happen. You need to make the static function public. The anonymous function doesn't run inside the scope of MyClass, and therefore doesn't have access to private methods contained within it.

这篇关于从 PHP 匿名函数访问变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆