{"id":76,"date":"2006-10-28T12:17:16","date_gmt":"2006-10-28T10:17:16","guid":{"rendered":"http:\/\/www.nivas.hr\/blog\/2006\/10\/29\/76\/"},"modified":"2006-11-18T16:47:40","modified_gmt":"2006-11-18T14:47:40","slug":"76","status":"publish","type":"post","link":"https:\/\/www.nivas.hr\/blog\/2006\/10\/28\/76\/","title":{"rendered":"some notes on php design"},"content":{"rendered":"<p>Today, I have read on <a target=\"_blank\" href=\"http:\/\/metapundit.net\/sections\/blog\/code_smells_and_design_principles\">metapundit.net<\/a> some thoughts on how to improve php coding. Don&#8217;t see the real point in this, except the faster coding. Readability and maintenance is degraded slightly.<\/p>\n<p>Update &#8211; 18.11.2006. &#8211; After taking some time to think about this, I have to agree with MetaPundit. Putting var names into array, and looping trough them makes code more maintainable. But I still have some issues with this, regarding more complex stuff.<br \/>\n<!--more--><\/p>\n<pre>Example 1:<\/pre>\n<pre><code>class foo{\r\nfunction foo($duration, $height, $width, $quality){\r\n$this->_duration = $duration;\r\n$this->_height = $height;\r\n$this->_width = $width;\r\n$this->_quality = $quality;\r\n}\r\n\/* Useful code goes here*\/<\/code><\/pre>\n<pre><code>...<\/code><\/pre>\n<pre><code>class foo{\r\nfunction foo($duration, $height, $width, $quality){\r\nforeach(array('duration', 'height', 'width', 'quality') as $arg)\r\n{\r\n$this->{\"_$arg\"} = $$arg;\r\n}\r\n}<\/code><\/pre>\n<pre>\r\n<pre><code>Example 2:<\/code>\r\n<code \/><\/pre>\n<p>$row = $db->query('select * from foo');<br \/>\n$template->setVariable('fname',$row['fname']);<br \/>\n$template->setVariable('lname',$row['lname']);<br \/>\n$template->setVariable('zip',$row['zip']);<br \/>\n$template->setVariable('city',$row['city']);<br \/>\n$template->setVariable('state',$row['state']);<br \/>\n$template->setVariable('street',$row['street']);<code><br \/>\n$template->setVariable('county',$row['county']);<\/code><\/p>\n<pre><code>...<\/code><\/pre>\n<pre><code>$row = $db->query('select * from foo');\r\nforeach(array('fname','lname','zip','city','state','street','zip','county') as $field)\r\n$template->setVariable($field,$row[$field]);<\/code><code>\r\n...<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today, I have read on metapundit.net some thoughts on how to improve php coding. Don&#8217;t see the real point in this, except the faster coding. Readability and maintenance is degraded slightly. Update &#8211; 18.11.2006. &#8211; After taking some time to think about this, I have to agree with MetaPundit. Putting var names into array, and&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/76"}],"collection":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}