Accessing a public property of a class within the class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Accessing a public property of a class within the class

    I am having some difficulty using an array in my class
    let's say $_REQUEST['appData'] = array('foo'=>' ABC '}

    I am using:
    php 5.3
    on a windows xP platform
    running an Apache server v 2.xx
    in a FireFox v 25.01 browser

    use firephp, I can see that $p has been populated with the array before I try to access it.


    What is the proper syntax for manipulating public variables within a class?

    Code:
    class aFill
    {
      public $p;
      private $c;
    
      function addStuff()
      {
       // this works 
       $this->c['myArray'] = array();
       $this->c['myArray'][0] = 'something';
    
       //returns error "[B]Undefined index: foo[/B]"
       $this->p['foo']= trim($this->p['foo']);
       
       return $this->p;
      }
    }
    
    $a = new aFill;
    $a->p = json_decode($_REQUEST['appData'], true);
    
    /*
    calling the method of the class to manipulate the $p property of the class
    */
    $response = $a->addStuff();
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Found my error. $_REQUEST['appData'] contained an array, I called parameters

    so it should have been $_REQUEST['appData']['parameters']
    Last edited by Claus Mygind; Dec 13 '13, 07:55 PM. Reason: found error in coding after many hours of looking at the same stuff.

    Comment

    Working...