0

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?

Brian
  • 1,951
  • 16
  • 56
  • 101
  • `on line 3780` If your file is really over 3k lines long, I think you're doing something wrong – Rizier123 Mar 03 '15 at 14:43
  • What do you mean? I have been trying to find a solution for the last 2-3 hours to no avail. I do not see anything wrong with my code. Data is returned from the script, but returned back to the page containing jQuery as NULL – Brian Mar 03 '15 at 14:47

1 Answers1

0

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...
Community
  • 1
  • 1
phatskat
  • 1,797
  • 1
  • 15
  • 32