{"id":352,"date":"2011-09-24T17:48:30","date_gmt":"2011-09-24T15:48:30","guid":{"rendered":"http:\/\/tronche.com\/blog\/less-technical\/uncategorized\/2011\/09\/php-equivalent-of-python-setattr\/"},"modified":"2019-04-13T11:06:17","modified_gmt":"2019-04-13T09:06:17","slug":"php-equivalent-of-python-setattr","status":"publish","type":"post","link":"https:\/\/tronche.com\/blog\/2011\/09\/php-equivalent-of-python-setattr\/","title":{"rendered":"PHP equivalent of python setattr"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>setattr(obj, name, value)<\/code><\/pre>\n\n\n<p>sets property name of obj to value in python.<\/p>\n<p>You can do the same in php with<br>$obj-&gt;$name = value<\/p>\n<p>note the $ in front of the name<br>$obj-&gt;name = value would be in python<br>setattr(obj, &#8216;name&#8217;, value)<br>or simply<br>obj.name = value<\/p>\n\n\n<pre class=\"wp-block-code\"><code>setattr(obj, name, value)<\/code><\/pre>\n\n\n\n<p>sets property name of obj to value in python.<\/p>\n\n\n\n<p>You can do the same in php with<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$obj->$name = value<\/code><\/pre>\n\n\n\n<p>note the $ in front of the name<br>\n$obj-&gt;name = value would be in python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setattr(obj, 'name', value)<\/code><\/pre>\n\n\n\n<p>or simply<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>obj.name = value<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>sets property name of obj to value in python. You can do the same in php with$obj-&gt;$name = value note the $ in front of <a class=\"mh-excerpt-more\" href=\"https:\/\/tronche.com\/blog\/2011\/09\/php-equivalent-of-python-setattr\/\" title=\"PHP equivalent of python setattr\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,1],"tags":[224,222],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-hack","category-uncategorized","tag-php","tag-python"],"_links":{"self":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":2,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":400,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/352\/revisions\/400"}],"wp:attachment":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}