在PHP我怎么能访问":私人和QUOT;阵列中的一个对象? [英] In PHP how can I access a ":private" array in an object?
问题描述
直到在 WP_Admin_Bar对象周围3.3beta1项
可以使用这种类型的语法的访问,例如改变的CSS类的现有的菜单项中的一个的:
Up until around 3.3beta1 items in the WP_Admin_Bar Object
could be accessed using this type of syntax, for example to change the CSS class of one of the existing menu items:
$wp_admin_bar->menu->{'wp-logo'}['meta']['class'] = 'new-class';
在运行时的print_r($ wp_admin_bar)
输出看起来是这样的:
WP_Admin_Bar Object
(
[menu] => stdClass Object
(
[my-account] => Array
(
不过,各地的版本 3.3beta2
更改菜单项的CSS类不再起作用上述语法,并从 print_r的输出($ wp_admin_bar )
揭示了一个不同的结构,该对象:
However, around version 3.3beta2
the above syntax for changing a menu item's CSS class no longer works, and the output from print_r($wp_admin_bar)
reveals a different structure for that object:
WP_Admin_Bar Object
(
[nodes:WP_Admin_Bar:private] => Array
(
[my-account] => stdClass Object
(
[id] => my-account
)
我知道这个词preSS可能不希望我的菜单摆弄这样的,如果有这样做更规范的方式,我喜欢使用它,但据我所知,只有两个可用的功能来修改管理栏, add_menu_item
和 remove_menu_item
,而这些不给灵活地做事像改变现有的菜单项的属性。
I realize that Wordpress may not want me fiddling with the menus this way, and if there was a more standardized way to do this I would love to use it, but as far as I know there are only two functions that are available to modify the admin bar, add_menu_item
and remove_menu_item
, and these do not give the flexibility to do things like changing the attributes of existing menu items.
要确认,我看着 WP-包括/类可湿性粉剂管理员-bar.php
很显然,字preSS已经改变了他们的定义方式变量。
To confirm, I looked at wp-includes/class-wp-admin-bar.php
it is clear that Wordpress has changed the way they define the variables.
老班
class WP_Admin_Bar {
var $menu;
var $proto = 'http://';
var $user;
新的类
class WP_Admin_Bar {
private $nodes = array();
private $root = array();
public $proto = 'http://';
public $user;
所以我的问题是,如果我有机会获得全球$ wp_admin_bar
的对象,是有我的方式,我可以访问节点内的对象:WP_Admin_Bar :私人
?如果没有,有另一种方式来获得这些对象,如创建一个扩展 WP_Admin_Bar
类的新类,然后从那里访问的对象?
So my question is if I have access to the global $wp_admin_bar
object, is there I way I can access the objects inside nodes:WP_Admin_Bar:private
? And if not, is there another way to get to these objects, such as creating a new class that extends the WP_Admin_Bar
class and then accessing the objects from there?
PS:我试图克服这一挑战不改变核心词preSS文件...
ps: I'm trying to overcome this challenge without changing the core Wordpress files...
链接到文件中:<一href=\"http://phpxref.ftwr.co.uk/word$p$pss/nav.html?wp-includes/class-wp-admin-bar.php.source.html\">http://phpxref.ftwr.co.uk/word$p$pss/nav.html?wp-includes/class-wp-admin-bar.php.source.html
推荐答案
将其更改为受保护的成员变量和扩展类。
Change them to protected member variables and extend the class.
谁写私人成员的类有效地作出类最终。这正好说明你应该总是写你的成员保护,除非有一个非常,非常好的理由不这样做。
Whoever wrote the class with private members effectively made the class "final". Which goes to show that you should always write your members as protected, unless there's a really, REALLY good reason to do otherwise.
希望帮助...
这篇关于在PHP我怎么能访问&QUOT;:私人和QUOT;阵列中的一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!