Monday 3 December 2018

php - How can I access a property with an invalid name?

I'm adding data to a stdClass object that is going to be sent through a 3rd party API and so the names I am giving to the elements of this object are actually being defined by that external service.



$insertArray = array();
$insertArray[0] = new stdclass();
$insertArray[0]->Name = $name;

$insertArray[0]->PhoneNumber = $phone;


This was all working wonderfully until I came across a property with an invalid name:



$insertArray[0]->First.Name = $firstname;


So that isn't valid PHP syntax, so is there a way around this?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...