Modify an entry of a property which is array in PHP -


what quick way change entry of property array.

// generates illegal string offset ... $this->propertyarray['index'] = 'xxx'; 

i forgot mention property accessed dynamically, here's complete snippet:

class myobject {     public $dimensions = [         'width' => 100,         'height' => 200     ];      public function changeentryofarrayproperty($property, $entry, $value) {         // warning: illegal string offset 'width'         $this->$property[$entry] = $value;     } }  $obj = new myobject(); // warning: illegal string offset 'width' $obj->changeentryofarrayproperty('dimensions', 'width', 600); 

you need change how access dynamic property - see dynamically access object property array element in php

public function changeentryofarrayproperty($property, $entry, $value) {     // warning: illegal string offset 'width'     $this->{$property}[$entry] = $value; } 

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -