dounan9070 2013-05-17 23:37
浏览 64

在一些其他函数中包装全局对象的访问器方法

I do a lot of stuff specifically with PHP and WordPress, and I've come across this concept quite often throughout the WordPress application; although, this question isn't specific to WordPress. I'll demonstrate with an example.

Say there is some global object of a class.

global $foo;
$foo = new Foo();

And then this class has some sort of accessor method that could be used with our global object.

global $foo;
$bar = $foo->get_bar();

Well, often I see this wrapped in a general function that takes care of tapping into the object's method, essentially hiding that part of it, making it more simple to access that item.

function wp_get_bar() {
    global $foo;
    return $foo->get_bar();
}

And so a developer using the application could just do this where ever they wanted without knowing about the $foo global object specifically:

$bar = wp_get_bar();

I'm just curious if this is a general computer science concept? If so, is there a name for it? Or is this something I can read more about somewhere?

  • 写回答

2条回答 默认 最新

  • dongyuan1902 2013-05-18 00:28
    关注

    When Wordpress was created, OOP wasn't very popular. In fact, OOP became more serious with PHP5, and Wordpress started with... PHP3?

    In addition, I think that to make it easy for newbie users, Wordpress developers opted using procedural functions instead of objects and classes. It's simpler if you don't have a deep knowledge of WP core.

    I don't think this has an specific name.

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备