J'utilise une classe PHP que quelqu'un a écrite pour s'interfacer avec l'API BaseCamp.Comment accéder à cette propriété d'objet avec un nom de trait d'union?
L'appel particulier que je fais est de récupérer les éléments dans une liste de tâches, qui fonctionne bien.
Mon problème est, je ne suis pas sûr comment accéder à la seule propriété todo-items
de l'objet qui est retourné. Voici le var_dump de l'objet retourné:
object(stdClass)[6]
public 'completed-count' => string '0' (length=1)
public 'description' => string 'Description String' (length=89)
public 'id' => string '12345' (length=7)
public 'milestone-id' => string '' (length=0)
public 'name' => string 'Error Reports' (length=13)
public 'position' => string '1' (length=1)
public 'private' => string 'false' (length=5)
public 'project-id' => string '58904' (length=7)
public 'tracked' => string 'false' (length=5)
public 'uncompleted-count' => string '1' (length=1)
public 'todo-items' =>
object(stdClass)[3]
public 'todo-item' =>
object(stdClass)[5]
public 'completed' => string 'false' (length=5)
public 'content' => string 'content string here' (length=133)
public 'created-on' => string '2009-04-16T20:33:31Z' (length=20)
public 'creator-id' => string '23423' (length=7)
public 'id' => string '234' (length=8)
public 'position' => string '1' (length=1)
public 'responsible-party-id' => string '2844499' (length=7)
public 'responsible-party-type' => string 'Person' (length=6)
public 'todo-list-id' => string '234234' (length=7)
public 'complete' => string 'false' (length=5)
Comment puis-je accéder à la partie todo-items
de cet objet?
theeeere nous allons, c'est la syntaxe que je cherche. Merci! – Ian
Bien que ce soit court et doux (et ce que je recommanderais), vous pouvez également le faire via des variables: '$ todolist = 'todo-list'; $ x -> $ todolist' – Christian
* Réponse très tardive *, avec PHP> 5.5, il existe de meilleures solutions. Soit 'cast 'l'objet à un tableau, ou essayez' get_object_vars() '. –