www.webdeveloper.com
Results 1 to 7 of 7

Thread: Trying to get property of non-object in class OLAPdatabase.php

  1. #1
    Join Date
    Aug 2014
    Posts
    5

    Trying to get property of non-object in class OLAPdatabase.php

    I have an array of objects. I have verified that the data is in the object and array with var_dump, but when I pass the array of objects to another class, and try to access a property in the object, I get the above error message. I'm sure I'm doing something wrong, but I'm not sure what since OO php is new to me, as well as php in general. I'm more of a C#/C++ person. Any help would be greatly appreciated!

    This is how I put the data in the object and array:

    ViseUpload.php:


    PHP Code:
    require_once( "../classes/class.OLAPdatabase.php");
        require_once(
    "class.ViseParameter.php");
     
        
    $OLAPdb = new OLAPdatabase;
        
    $ViseParameter NULL;
       
        for(
    $i=;$i<count($_GET["ID"]) ;$i++){
           
    $ID $_GET["ID"][$i];
           
    $Desc $_GET["Desc"][$i];
           
    $Yevaluation $_GET["Yevaluation"][$i];
           
    $Mevaluation $_GET["Mevaluation"][$i];
           
    $Cevaluation $_GET["Cevaluation"][$i];
           
    $Kevaluation $_GET["Kevaluation"][$i];
           
    $comment $_GET["comment"][$i];
       
           
    $ViseParameter = new ViseParameter();
           
    $ViseParameter->parameterID=$ID;
           
    $ViseParameter->parameterDesc=$Desc;
           
    $ViseParameter->Yevaluation=$Yevaluation;
           
    $ViseParameter->Mevaluation=$Mevaluation;
           
    $ViseParameter->Cevaluation=$Cevaluation;
           
    $ViseParameter->Kevaluation=$Kevaluation;
           
    $ViseParameter->Comments=$comment;
       
           
    $arrViseParameters[$i] = $ViseParameter;
          
           
    var_dump($ViseParameter);
          
           
    var_dump($arrViseParameters);
          
           
    var_dump($arrViseParameters[$i]);
        }
        
    $OLAPdb->StoreViseData($arrViseParameters); 
    My method below is where I'm having the error message:


    class.OLAPdatabase.php:


    PHP Code:
    require_once("class.ViseParameter.php");

    function 
    StoreViseData($arr )      
       
    //--------------------------:--------------------------------
       // Pass this function values to store in OLAP DB from visual evaluation
       // entry table.
       //----------------------------------------------------------
       
    {
           echo 
    "OLAP DB upload requested";
          
           foreach(
    $arr as $tempObj)
           {
               
    $ViseParameter = new ViseParameter();
               
    $ViseParameter $tempObj;    //this used to be more direct from array but it was giving same err msg
               
    $ID$ViseParameter->parameterID//this gives error message
               
    var_dump($ID);
           }
          
          
    //will send to DB next
       
    // END - StoreViseData 
    This is what my class.ViseParameter.php looks like:


    PHP Code:
    <?php 

    class ViseParameter 

       var 
    $parameterID null;
       var 
    $parameterDesc null;
       var 
    $Yevaluation null;
       var 
    $Mevaluation null;
       var 
    $Cevaluation null;
       var 
    $Kevaluation null;
       var 
    $Comments null;
      
       
    //**********************************************************
       //                  -[ F_u_n_c_t_i_o_n_s ]-
       //**********************************************************
       
    function __construct()
       { }  
    // END - Constructor
       //**********************************************************
       
    function __destruct()
       { }  
    // END - Destructor
       //**********************************************************
      
    ?>

  2. #2
    Join Date
    Aug 2014
    Posts
    5
    If you have a better suggestion for how to do this, I'd appreciate that too. Thanks!

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    I might redefine the ViseParameter class to something more along these lines:
    PHP Code:
    <?php

    class ViseParameter
    {
        
    // "var" is PHP4, so assuming you're using PHP 5 now, define visibility instead
        
    public $parameterID// default value is null, so no need to assign it
        
    public $parameterDesc;
        public 
    $Yevaluation;
        public 
    $Mevaluation;
        public 
    $Cevaluation;
        public 
    $Kevaluation;
        public 
    $Comments;

        public function 
    populate(Array $data)
        {
            foreach(
    $data as $key => $value)
            {
                if(
    property_exists($this$key))
                {
                    
    $this->$key $value;
                }
                else
                {
                    throw new 
    Exception("Invalid property name '$key'");
                }
            }
        }
    }

    // example usage:

    $testData = array(
        
    'parameterID'    => 1,
        
    'parameterDesc' => 'This is a test.'
    );
    $vp = new ViseParameter();
    $vp->populate($testData);
    var_dump($vp);
    (Okay, so I probably wouldn't do it much like that at all, but that's fairly close to your original design. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Aug 2014
    Posts
    5
    The thing is, I have a GET on my form/table, and it winds up in UpdateVise.php with the GET needing to be processed. Plus, I'm still not sure why it won't let me access the data in the class once it's created. It's php version 5.3.

  5. #5
    Join Date
    Aug 2014
    Posts
    5
    I mean ViseUpload.php

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Okay, I've looked a bit more closely at this. If I'm reading it right, by the time you call this line in the first bit of code...
    PHP Code:
    $OLAPdb->StoreViseData($arrViseParameters); 
    ...$arrViseParameters should be an array of ViseParameter objects. So in the StoreViseData() method, there is no need to be instantiating more ViseParameter objects.
    PHP Code:
    function StoreViseData($arr )      
       
    //--------------------------:--------------------------------
       // Pass this function values to store in OLAP DB from visual evaluation
       // entry table.
       //----------------------------------------------------------
       
    {
           echo 
    "OLAP DB upload requested";
          
           foreach(
    $arr as $tempObj)
           {
               
    // could add some defensive code here if desired
               // to verify the $tempObj is a ViseParameter:
               
    if( ! is_a($tempObj'ViseParameter'))
               {
                   throw new 
    Exception("Not a ViseParameter!");
               }
               
    // now just treat $tempObj as what it is: an instance of ViseParameter:
               
    $ID$tempObj->parameterID;
               
    var_dump($ID);
           }
          
          
    //will send to DB next
       
    // END - StoreViseData 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Aug 2014
    Posts
    5
    I thought I posted a reply to this and I'm not sure where it went. Here goes again:

    I added the is_a that you have above and it was showing error for the Exception line instead of the "Not a ViseParamenter" like it was supposed to. I took another look in ViseUpload.php, and it turns out I had a stray
    PHP Code:
    $arrViseParameters $ViseParameter
    that was after my for loop (populating the classes and array) that was corrupting my array, so all my logging wasn't accurate for what was being sent to the OLAP class.

    Thanks for the help!

    M

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles