dongren9966 2015-03-03 14:41
浏览 73

致命错误:无法访问.. PEAR-PHP / PHP中的空属性

I am using a jQuery method to pass data to a php method and get a response so that I could re-use the returned data.

I am getting an error:

DO_LicenseCount: find: CHECK autofetchd
DO_LicenseCount: find: DONE
DO_LicenseCount: FETCH: a:1:{s:12:"LicenseCount";s:2:"10";}
DO_LicenseCount: fetchrow LINE: LicenseCount = 10
DO_LicenseCount: fetchrow: LicenseCount DONE

Fatal error: Cannot access empty property in C:\PROJECTS\BRIAN\AMS\Web Application\inc\pear\DB\DataObject.php on line 3780

I am using a WAMP stack - PHP 5.1.6 and PearPHP.

jQuery:

<script>

function GetLicenseCount()
    {
        var SoftwareTypeFK = document.getElementById("sldSoftwareTypeList").value;
        var SoftwareNameFK = document.getElementById("SoftwareTypeList").value;

        console.log(SoftwareTypeFK);
        console.log(SoftwareNameFK);


            $.ajax({
                       type: "GET",
                       url: "/AMS_LOCAL/Modules/SoftwareLicenseAllocations/GetLicenseCount.php",
                       data: {SoftwareTypeFK: SoftwareTypeFK, SoftwareFK: SoftwareNameFK},
                       success: function(result){
                         $("txtLicenseCount").text(result);
                         console.log(result);
                       }
                     });
    };


</script>

GetLicenseCount.php:

<?php

//Local include path format
                set_include_path('C:\PROJECTS\BRIAN\AMS\Web Application;C:\PROJECTS\BRIAN\AMS\Web Application\inc\pear;C:\PROJECTS\BRIAN\AMS\Web Application\js;');

                //Search Screen
                require_once('vars.php');
                require_once('funcs.php');

        $SoftwareTypeID = $_GET['SoftwareTypeFK'];
        $SoftwareNameID = $_GET['SoftwareFK'];

        var_dump($SoftwareTypeID);
        var_dump($SoftwareNameID);

        DO_Common::DebugLevel(5);
         $LicenseCountOptions = DO_Common::toAssocArray(array(
        //$LicenseCountOptions = DO_LicenseCount::toAssocArray(array(
                'tableName' => 'LicenseCount'
                ,'selectAdd' => 'LicenseCount'
                ,'whereAdd' => 'SoftwareFK=' . $SoftwareNameID  . ' AND sldSoftwareTypeFK=' . $SoftwareTypeID
                 ));

         var_dump($LicenseCountOptions);

         echo $LicenseCountOptions;
         var_dump($LicenseCountOptions);
?>

part of DataObject.php:

  function toValue($col,$format = null) 
    {
        if (is_null($format)) {
            **return $this->$col;**
            echo $col;
        }
        $cols = $this->table();
        switch (true) {
            case (($cols[$col] & DB_DATAOBJECT_DATE) &&  ($cols[$col] & DB_DATAOBJECT_TIME)):
                if (!$this->$col) {
                    return '';
                }
                $guess = strtotime($this->$col);
                if ($guess != -1) {
                    return strftime($format, $guess);
                }
                // eak... - no way to validate date time otherwise...
                return $this->$col;
            case ($cols[$col] & DB_DATAOBJECT_DATE):
                if (!$this->$col) {
                    return '';
                } 
                $guess = strtotime($this->$col);
                if ($guess != -1) {
                    return strftime($format,$guess);
                }
                // try date!!!!
                require_once 'Date.php';
                $x = new Date($this->$col);
                return $x->format($format);

            case ($cols[$col] & DB_DATAOBJECT_TIME):
                if (!$this->$col) {
                    return '';
                }
                $guess = strtotime($this->$col);
                if ($guess > -1) {
                    return strftime($format, $guess);
                }
                // otherwise an error in type...
                return $this->$col;

            case ($cols[$col] &  DB_DATAOBJECT_MYSQLTIMESTAMP):
                if (!$this->$col) {
                    return '';
                }
                require_once 'Date.php';

                $x = new Date($this->$col);

                return $x->format($format);


            case ($cols[$col] &  DB_DATAOBJECT_BOOL):

                if ($cols[$col] &  DB_DATAOBJECT_STR) {
                    // it's a 't'/'f' !
                    return ($this->$col == 't');
                }
                return (bool) $this->$col;


            default:
                return sprintf($format,$this->col);
        }               

    }

The problematic line is is the one enclosed in ** return $this->$col; (line 3780).

I searched over Google and what I found is that I should turn return $this->$col; to return $this->col;, however this is found by default in the PEAR package and I did not do any modifications to the code. When I change it, a number of errors turn up.

Am I missing something I'm not seeing here?

  • 写回答

1条回答 默认 最新

  • douhe4336 2015-03-03 15:08
    关注

    Not sure where to start as I can't see which line is mentioned in the error but this

    Fatal error: Cannot access empty property 
    

    Usually means there is something wrong when accessing a member of an object. An example of what causes this can be seen in this answer. It seems like you may be doing something like this:

    <?php
    
    class FooBar
    {
        public function baz()
        {
            $col = 'someprop';
            $this->$col = 'weeee'; // There is no 'someprop' member of $this
        }
    }
    

    If you can provide the exact line referenced in the error, that could narrow it down a lot.

    In your code, you have

    function toValue($col,$format = null) 
    {
        if (is_null($format)) {
            **return $this->$col;**
            echo $col;
        }
     // snip ...
    

    Put the echo line before the return, and do a die to stop execution and see what's going on. Essentially, the script is trying to access $this->$col when the value of $col is not a property on $this - so if $col is the string 'something', there is no property $this->something.

    Removing the $ isn't the issue, and it probably should be there. You could try modifying the function such as:

    function toValue($col,$format = null) 
    {
        if(is_null($format)) {
            if(isset($this->$col))
                return $this->$col;
            else
                return null; // Or false or whatever you would like
        }
    
        // snip...
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来