How do I access a PHP object attribute having a dollar sign?

后端 未结 5 2120
清歌不尽
清歌不尽 2020-11-29 12:17

I have a PHP Object with an attribute having a dollar ($) sign in it.

How do I access the content of this attribute ?

Example :

echo $object-         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 12:42

    1. With variable variables:

      $myVar = 'variable$WithDollar';
      echo $object->$myVar;
      
    2. With curly brackets:

      echo $object->{'variable$WithDollar'};
      

提交回复
热议问题