How to declare dynamic PHP class with {'property-names-like-this'}

后端 未结 3 1652
心在旅途
心在旅途 2021-01-14 15:58

Im rewriting application from .NET to PHP. I need to create class like this:

class myClass
{
    public ${\'property-name-with-minus-signs\'} = 5;
    public         


        
3条回答
  •  伪装坚强ぢ
    2021-01-14 16:33

    I used code like this:

    class myClass
    {
    
        function __construct() {
    
            // i had to initialize class with some default values
            $this->{'fvalue-string'} = '';
            $this->{'fvalue-int'} = 0;
            $this->{'fvalue-float'} = 0;
            $this->{'fvalue-image'} = 0;
            $this->{'fvalue-datetime'} = 0;   
        }
    }
    

提交回复
热议问题