搜索

首页  >  问答  >  正文

php - Call to a member function get() on null

请大家先看一下下面的问题,帮忙解决一下,谢谢啦!

本地搭建的php+nginx环境,thinkphp3.1的框架。

Call to a member function get() on null D:\phpStudy\WWW\qj\ThinkPHP\Extend\Driver\TagLib\TagLibGyfx.class.php 第 589 行.
Call to a member function get() on null D:\phpStudy\WWW\qj\ThinkPHP\Extend\Driver\TagLib\TagLibGyfx.class.php 第 589 行.
错误位置

FILE: D:\phpStudy\WWW\qj\ThinkPHP\Lib\Core\Think.class.php  LINE: 277
TRACE

[17-02-25 08:51:02] D:\phpStudy\WWW\qj\ThinkPHP\Lib\Core\Think.class.php (277) halt(Call to a member function get() on null D:\phpStudy\WWW\qj\ThinkPHP\Extend\Driver\TagLib\TagLibGyfx.class.php 第 589 行.)
[17-02-25 08:51:02] D:\phpStudy\WWW\qj\ThinkPHP\Lib\Core\Think.class.php (292) Think::appError(1, Call to a member function get() on null, D:\phpStudy\WWW\qj\ThinkPHP\Extend\Driver\TagLib\TagLibGyfx.class.php, 589)
[17-02-25 08:51:02] () Think::fatalError()

ThinkPHP3.1.2 { Fast & Simple OOP PHP Framework } -- [ WE CAN DO IT JUST THINK ]

本地自定义标签文件目录:
D:phpStudyWWWqjThinkPHPExtendDriverTagLibTagLibGyfx.class.php

问题所在代码:

/**
 * 自定义主导航标签
 * <gyfx:navigation name='navigation' row='8' position="middle"></gyfx:navigation>
 * @param type $attr
 * @param type $content
 */
public function _navigation($attr, $content){
    $parseStr = '';
    $tag = $this->parseXmlAttr($attr, 'navigation');
    //dump($tag);die();
    $name = $tag['name'];
    $row = !empty($tag['row']) ? $tag['row'] : '12';
    $position = !empty($tag['position']) ? $tag['position'] : 'top';
    //实例化缓存
    if(C('DATA_CACHE_TYPE') == 'MEMCACHED' && C('MEMCACHED_OCS') == true){
        $memcaches = new Cacheds();
    }else{
        $memcaches = new Caches();
    }
    //生成一个用来保存 namespace 的 key  
    if($memcaches->getStat()){
        $ns_key = $memcaches->C()->get(CI_SN."_namespace_key");  
        //如果 key 不存在,则创建,默认使用当前的时间戳作为标识
        if($ns_key===false) $memcaches->C()->set(CI_SN."_namespace_key",time());  
    }
    //根据tag获取缓存key
    $cache_key = json_encode($tag).CI_SN;
    $cache_key = $ns_key.$cache_key;
    if($memcaches->getStat() && ini_get('memcache.allow_failover')&& $ary_return = $memcaches->C()->get($cache_key)){
        $list = json_decode($ary_return,true);
       
    }else{
        $list = D("Nav")->where(array('n_status'=>'1','n_position'=>$position))
        ->field('n_id as nid,n_name as nname,n_url as nurl,n_target as ntarget, n_order as norder ')
        ->order(array('n_order' => 'asc'))->limit($row)->select();
        //处理数据
        if(!empty($list) && is_array($list)){
            foreach($list as &$slist){
                if(strstr($slist['nurl'],"?")){
                    $slist['nurl'] = 

$slist['nurl'].'&name='.$slist['nname'];
                    }else{
                        $slist['nurl'] = $slist['nurl'];
                    }
                }
            }
            if($memcaches->getStat() && ini_get('memcache.allow_failover')){
                $memcaches->C()->set($cache_key,json_encode($list));
            }
        }
        $count = count($list);
        $str_list = var_export($list, true);
        $parseStr = $parseStr . "<?php $$name = " . $str_list . "; ?>";
        $parseStr = $parseStr . "<?php \$nav_count = " . $count . "; ?>";
        $parseStr = $parseStr . '<volist name="nav" id="' . $name . '" >' . $content . '</volist>';
        return $parseStr;
    }
第589行:$ns_key = $memcaches->C()->get(CI_SN."_namespace_key");


阿神阿神2794 天前1544

全部回复(3)我来回复

  • 阿神

    阿神2017-04-11 10:00:57

    你得看看 $memcaches->C()为什么是空的啊

    回复
    0
  • 大家讲道理

    大家讲道理2017-04-11 10:00:57

    谢邀~

    $memcaches->C()

    返回值是null不是一个对象,你再断点看看

    回复
    0
  • 阿神

    阿神2017-04-11 10:00:57

    问题解决了,大家看下我的解决方法,请问下这是什么原因啊?

    这样改的也可以,怎么回事啊??

    回复
    0
  • 取消回复