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

时间:2015-03-03 14:41:37

标签: php jquery pear

我正在使用jQuery方法将数据传递给php方法并获得响应,以便我可以重新使用返回的数据。

我收到错误:

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

我正在使用WAMP堆栈 - PHP 5.1.6和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);
?>

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);
        }               

    }

有问题的行是** return $this->$col;(第3780行)中的一行。

我在Google上搜索过,我发现我应该将return $this->$col;变为return $this->col;,但默认情况下,这是在PEAR包中找到的,我没有对代码进行任何修改。当我改变它时,会出现许多错误。

我错过了一些我没有看到的东西吗?

1 个答案:

答案 0 :(得分:0)

不确定从哪里开始,因为我无法看到错误中提到哪条线但是

Fatal error: Cannot access empty property 

通常表示访问对象成员时出错。在this answer中可以看到导致这种情况的一个例子。看起来你可能会做这样的事情:

<?php

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

如果您可以提供错误中引用的确切行,则可能会将其缩小很多。

在您的代码中,您有

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

在返回之前放置echo行,并执行骰子以停止执行并查看正在发生的事情。从本质上讲,当$this->$col的值不是$col上的属性时,脚本会尝试访问$this - 所以如果$col是字符串'something',那么不属性$this->something

删除$不是问题,它可能应该存在。您可以尝试修改功能,例如:

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...