Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$this->"variable value" OOP PHP

Tags:

php

I'm wondering if it's possible, and in case it is, how shoud I achive that:

$this->id <-- i have such thing. but to make it more usable i'd like to have $this->(and here to change the values)

for ex: I might have $this->id $this->allID $this->proj_id

how can I make so that actually I have $this->($myvariable here, that has a unique name in it)?

like image 468
mrGott Avatar asked Jan 19 '23 13:01

mrGott


1 Answers

You can simply use this:

 $variable = 'id';
 if ( isset ( $this->{$variable} )  ) 
 {
    echo $this->{$variable};
 }
like image 171
GordyD Avatar answered Jan 24 '23 19:01

GordyD