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

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -