Php 试图理解与zend相关的一些函数
这篇文章摘自xenfro/Application.php,虽然评论很清楚,但仍有一些问题:Php 试图理解与zend相关的一些函数,php,zend-framework,Php,Zend Framework,这篇文章摘自xenfro/Application.php,虽然评论很清楚,但仍有一些问题: $instance=self::getInstance()这行在这里是什么意思 $instance->lazyLoad我找不到这个方法的声明:lazyLoad,它也是Zend文件吗 $instance->offsetGet($index),我在SPL.php中看到了它的声明,它是: 公共函数offsetGet($index){},但它在{}内是空的,那么这个函数是如何实现的呢 下面是关于你的三个问题的一些
$instance=self::getInstance()代码>这行在这里是什么意思李>
$instance->lazyLoad代码>我找不到这个方法的声明:lazyLoad,它也是Zend文件吗
$instance->offsetGet($index)
,我在SPL.php中看到了它的声明,它是:
公共函数offsetGet($index){}
,但它在{}内是空的,那么这个函数是如何实现的呢李>
下面是关于你的三个问题的一些简短解释
1$instance=self::getInstance();这条线在这里是什么意思?
答案1。getInstance方法用于在不执行$test=new class_name()的情况下获取该类实例;
getInstance方法是静态的,因此您可以在不声明新类名称()的情况下获取该类实例;
在getInstance方法中,其检查是否设置了_instance?如果未设置,则创建自己的类实例,然后返回该实例
2$实例->懒散负载;我找不到这个方法的声明:lazyLoad,它也是Zend文件吗?
答案2。您可以从下面的链接了解懒虫,以便更好地了解懒虫
3$instance->offsetGet($index),我在SPL.php中看到了它的声明,它是:公共函数offsetGet($index){},但它在{}中是空的,那么这个函数是如何实现的呢?
答案3。此方法可以从Zend_Registry类型的对象调用,也可以静态调用。在后一种情况下,它使用存储在类中的默认静态实例
参数:
字符串$index-获取与$index关联的值
返回:
混合的
例外情况:
如果没有为$index注册任何条目,则Zend_异常
如果我能为您提供更多帮助,请告诉我。get
来自Zend/Registry.php感谢您的帮助。这有助于我更好地理解它,完全理解它可能需要时间。
/**
* getter method, basically same as offsetGet().
*
* This method can be called from an object of type Zend_Registry, or it
* can be called statically. In the latter case, it uses the default
* static instance stored in the class.
*
* @param string $index - get the value associated with $index
* @return mixed
* @throws Zend_Exception if no entry is registerd for $index.
*/
public static function get($index)
{
$instance = self::getInstance();
if (!$instance->offsetExists($index))
{
if ($instance->lazyLoad($index, $return))
{
return $return;
}
else
{
throw new Zend_Exception("No entry is registered for key '$index'");
}
}
return $instance->offsetGet($index);
}
...
public static function getDb()
{
return self::get('db');
}
...