在PHP中,可以调用静态方法,就好像它们是实例方法一样:
class A {
public static function b() {
echo "foo";
}
}
$a = new A;
A::b(); //foo
$a->b(); //foo
Run Code Online (Sandbox Code Playgroud)
有没有办法确定b()
方法是否静态调用?
我已经尝试isset($this)
但在两种情况下它都返回false,并且debug_backtrace()
似乎表明这两个调用实际上都是静态调用
array(1) {
[0]=>
array(6) {
["file"]=>
string(57) "test.php"
["line"]=>
int(23)
["function"]=>
string(1) "b"
["class"]=>
string(1) "A"
["type"]=>
string(2) "::"
["args"]=>
array(0) {
}
}
}
Foo
array(1) {
[0]=>
array(6) {
["file"]=>
string(57) "test.php"
["line"]=>
int(24)
["function"]=>
string(1) "b"
["class"]=>
string(1) "A"
["type"]=>
string(2) "::"
["args"]=>
array(0) {
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要通过将其转换为数组来访问char*的内容
这是一个演示:
from ctypes import *
foo = (c_char * 4)()
foo.value = "foo"
print foo.raw # => 'foo\x00'
foo_ptr = cast(foo, c_char_p)
print foo_ptr.value # => 'foo'
Run Code Online (Sandbox Code Playgroud)
现在我想将foo_ptr转换回(c_char*4).这些都不奏效
foo_ = (c_char * 4)(foo_ptr)
foo_ = cast(foo_ptr, c_char * 4)
Run Code Online (Sandbox Code Playgroud)