PHP equivalent of python setattr

setattr(obj, name, value)

sets property name of obj to value in python.

You can do the same in php with
$obj->$name = value

note the $ in front of the name
$obj->name = value would be in python
setattr(obj, ‘name’, value)
or simply
obj.name = value

setattr(obj, name, value)

sets property name of obj to value in python.

You can do the same in php with

$obj->$name = value

note the $ in front of the name
$obj->name = value would be in python

setattr(obj, 'name', value)

or simply

obj.name = value

Be the first to comment

Leave a Reply

Your email address will not be published.