Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Elliot_putt's avatar

PHP STD Class and Objects

Quick Question what does it mean when an STD Class object has quotes around the key?

 +"subject": "testing - "
  +createSubject: "test"
0 likes
8 replies
Elliot_putt's avatar

@Sinnbeck SO the one with speech marks is this code

   $object = new \stdClass();
    $object->subject ='testing' . " - " ;

The one without is just a construct parameter

  public function __construct(
        public ?string        $createSubject = 'test',
Sinnbeck's avatar

@Elliot_putt So you wrote those two lines and the output above just magically appeared? Or are you doing dd() or dump() or var_dump() or print_r() ? The first one looks like json, and in json the key is always wrapped in quotes

1 like
Elliot_putt's avatar

@Sinnbeck Yes Correct, just to put it into perspective it's weird I am writing code for an API and it will only accept the JSON body if it's formatted with the string, I don't know haha weird.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Elliot_putt Yeah you need keys to be wrapped with "". That is the json spec. But laravel does this for you automatically. No need to do it manually.

return response()->json($someData);

Please or to participate in this conversation.