【发布时间】:2012-06-30 14:09:52
【问题描述】:
我正在尝试在公共静态函数中使用 PHP 函数,就像这样(我已经缩短了一点):
class MyClass {
public static function first_function() {
function inside_this() {
$some_var = self::second_function(); // doesnt work inside this function
}
// other code here...
} // End first_function
protected static function second_function() {
// do stuff
} // End second_function
} // End class PayPalDimesale
那时我收到错误“无法访问 self:: 当没有活动的类范围时”。
如果我在inside_this 函数之外调用second_function,它可以正常工作:
class MyClass {
public static function first_function() {
function inside_this() {
// some stuff here
}
$some_var = self::second_function(); // this works
} // End first_function
protected static function second_function() {
// do stuff
} // End second_function
} // End class PayPalDimesale
我需要做什么才能在inside_this 函数中使用second_function?
【问题讨论】:
-
你试过闭包吗?
function inside_this() use($self) { -
我意识到
self不是变量为时已晚...