PHP: reflection, "non well formed numeric value encountered" setting array index -
i haven't been able find specific issue. in class need take associative array , put it's values in class variables. sub-arrays need converted objects. conversion objects happening in following code:
foreach ($value $key2 => $value2) { $object = new $object_str($value2); $this->$key[$object->getid()] = $object; }
$value comes outer foreach loop.
$object_str contains name of object has created,
this: martkuper\onepagecrm\contacts\contactsurl
the input array this:
[ 'url' => [ 'type' => 'website', 'value' => 'google.com' ] ]
it should create contactsurl object , add $url class variable (which array) based on class' internal random id (uniqid()). because don't know how many 'url' entries input array have, needs happen dynamically. hence
$this->$key[$object->getid()]
the error occurs on index of $key (url) array. seems doesn't take string index. i've tried putting hardcoded strings in
$this->$key['test]
that doesn't work either. when put integer in
$this->$key[1]
it work. converting string integer not option. break parser class used many other classes.
i've solved issue doing following:
$this->{$key}[$object->getid()] = $object;
what happening tried take index of $key
variable ($key[$object->getid()]
) since $key
isn't array, failed. needed take index of class variable $key
represents instead.
Comments
Post a Comment