如何使用点访问变量


How to access variable with dot

这是我var_dump($GLOBALS['pagination']);的一部分:

object(VmPagination)[376]
  ...
  public 'pages.total' => float 4
  public 'pages.current' => float 1
  public 'pages.start' => int 1
  public 'pages.stop' => float 4
  ...

有什么pages.total想法吗?我试过$GLOBALS['pagination']->pages.current,但它不起作用。

使用{}表示法:

$foo->{'bar.baz'} = 'qux';

例如:

php > $x = new StdClass();
php > $x->{'foo.bar'} = 'baz';
php > var_dump($x);
object(stdClass)#1 (1) {
  ["foo.bar"]=>
  string(3) "baz"
}
php > echo $x->foo.bar;
PHP Notice:  Undefined property: stdClass::$foo in php shell code on line 1
PHP Notice:  Use of undefined constant bar - assumed 'bar' in php shell code on line 1
bar
php > echo $x->{'foo.bar'};
baz