Deserialize a class within a class from a JSON query in PHP -


i have 2 classes (as in c#)

public class inside {     public string name {get;set;}     public int id {get;set;}     public string value {get;set;} }  public class outside {     public inside[] items {get;set;} } 

i query server , deserialize json values come outside class.

i've been asked if can port on php , i've come with

class inside {     public $name;     public $id;     public $value; }  class outside {     public array $item -> inside; 

with pretty else coming deserializing json php, casting?

for outside class deserialization.

no real surprise in doesn't work me (i stopped doing php years ago annoyed hell out of me php or nothing language - if don't see something, wrong)

the stumbler think how link inside class outside class in same way in c#?

i suggest pass in instance of inside class constructor of outside class , set instance property of class:

<?php class inside {     public $name;     public $id;     public $value; }  class outside {    private $inside;     public function __construct($inside) {       $this->inside = $inside;    } } ?> 

hopefully i'm understanding you're looking correctly. if not, please let me know. i'm not entirely familiar c# may misinterpreting you're trying accomplish.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -