<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7465788861246650010</id><updated>2012-02-16T14:56:19.444Z</updated><category term='PHP'/><category term='info'/><category term='JDK6'/><category term='remarks'/><title type='text'>Qwei's Lair</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://qwei.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://qwei.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jan Volmut aka Qwei</name><uri>http://www.blogger.com/profile/06428806852379817758</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/-y0mYfcM0YS0/Tetm2F8rA1I/AAAAAAAAABo/oDV2d5CxejE/s220/forSocNetwork.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7465788861246650010.post-1750347690295903269</id><published>2011-10-31T12:55:00.000Z</published><updated>2011-10-31T12:55:26.642Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><title type='text'>Php type cast</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Today I have been refactoring code which I wrote half an year ago and I made this mistake:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;I wrote&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;$url = $someUrl - $file-&amp;gt;getName();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;instead of&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;$url = $someUrl . $file-&amp;gt;getName();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;Suddenly the other code stopped working. However not for subtraction of strings but for something like fopen($url, "w") where $url was invalid. Of course. But question is what is really stored in $url?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;In my case there was "/folder/subfolder" in $someUrl and "something.txt" in $file-&amp;gt;getName(). The result in $url was ... tamtadadaa ... 0. Ok, when you think about it, it is simple. PHP takes both strings and convert them to numbers and those subtracts. Fine. As I said in my case the result was 0. That is because none of both strings starts with number. In case that the first string was "12 angry men" the result would be "12".&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;Other example, first string is "12 angry men" and second is "1 angry bird". The result is 11.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #444444;"&gt;&lt;span class="Apple-style-span" style="font-size: 15px; line-height: 19px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;There are more similar things in php and you should know them or you'll be surprised one day. For example try &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;echo 0 == "Hello world"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7465788861246650010-1750347690295903269?l=qwei.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://qwei.blogspot.com/feeds/1750347690295903269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://qwei.blogspot.com/2011/10/php-type-cast.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/1750347690295903269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/1750347690295903269'/><link rel='alternate' type='text/html' href='http://qwei.blogspot.com/2011/10/php-type-cast.html' title='Php type cast'/><author><name>Jan Volmut aka Qwei</name><uri>http://www.blogger.com/profile/06428806852379817758</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/-y0mYfcM0YS0/Tetm2F8rA1I/AAAAAAAAABo/oDV2d5CxejE/s220/forSocNetwork.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7465788861246650010.post-6133882695534543710</id><published>2011-04-12T00:35:00.000+01:00</published><updated>2011-04-12T00:35:12.663+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='remarks'/><title type='text'>Reference or new object</title><content type='html'>I was writing some function and I needed to return object. Actually that function just take object as parameter, drag out attributes, do some work and set new attribute to object and return it. When I am doing this I always consider if I should return the same object or create new one. The point is that when I return the same object, it may lead to confusing mistakes. Consider the piece of pseudo-code below:&lt;br /&gt;&lt;br /&gt;We have records in database and we store them as name part which look like "prefix-name" and data part. User puts the name and our dummy management add the prefix part. If we are dummy too and do this as object reference we are lost.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;class DummyObject {&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public $name;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public $data;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;class DatabaseManager {&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public function load(DummyObject $object){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Retrieve data from database and set them.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$this-&amp;gt;makeRightPath($object);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$object-&amp;gt;data = "Data with long story to tell";&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return $object;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//This sets the correct name of record in DB&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;private function makeRightPath(DummyObject $object) {&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$object-&amp;gt;name = "prefix-" . $object-&amp;gt;name;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return $object;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;$object = new DummyObject();&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;$object-&amp;gt;name = "DummyName";&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;$mng = new DatabaseManager();&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;$loaded = $mng-&amp;gt;load($object);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;echo $loaded-&amp;gt;name;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;The result of echo will be "prefix-DummyName" which user obviously does not want to see. In addition if we want to load (or save etc.) the same object again it leads to loading with name "prefix-prefix-DummyName" which is actually not in DB.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;I know this is not the best example of what I wanted to say (it is my first example ever) but it shows you how important is thinking about references in function calling.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7465788861246650010-6133882695534543710?l=qwei.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://qwei.blogspot.com/feeds/6133882695534543710/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://qwei.blogspot.com/2011/04/reference-or-new-object.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/6133882695534543710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/6133882695534543710'/><link rel='alternate' type='text/html' href='http://qwei.blogspot.com/2011/04/reference-or-new-object.html' title='Reference or new object'/><author><name>Jan Volmut aka Qwei</name><uri>http://www.blogger.com/profile/06428806852379817758</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/-y0mYfcM0YS0/Tetm2F8rA1I/AAAAAAAAABo/oDV2d5CxejE/s220/forSocNetwork.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7465788861246650010.post-2479019949624535185</id><published>2011-03-28T22:44:00.000+01:00</published><updated>2011-03-28T22:48:52.252+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDK6'/><category scheme='http://www.blogger.com/atom/ns#' term='remarks'/><title type='text'>Troubles with XML in JDK7 and changing to JDK6</title><content type='html'>Today I wanted to write some xml document which would be similar to some other xml in PHP project. So I opened the xml document and my NetBeans7Beta froze and I had to kill them through terminal. I tried several ways to force my NetBeans to open that document.&lt;br /&gt;After three or four time I had to kill them I tried to switch JDK. I had been using JDK7 so I wanted to change it to JDK6. I didn't find a way to do that inside NB IDE so I tried to google it. Many thanks to&amp;nbsp;&lt;a href="http://www.benmccann.com/dev-blog/change-the-netbeans-default-jdk/"&gt;this&lt;/a&gt;&amp;nbsp;article.&lt;br /&gt;I changed the line in NetBeans/etc/netbeans.conf to netbeans_jdkhome="path_to_java" (in my case path_to_java is /usr/lib/jvm/java-6-sun-1.6.0.24" - if you install java from repository, your path might be same).&lt;br /&gt;I don't actually know if the JDK7 was the cause of my problem but it seems to be ok after changing to JDK6.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7465788861246650010-2479019949624535185?l=qwei.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://qwei.blogspot.com/feeds/2479019949624535185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://qwei.blogspot.com/2011/03/troubles-with-xml-in-jdk7-and-changing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/2479019949624535185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/2479019949624535185'/><link rel='alternate' type='text/html' href='http://qwei.blogspot.com/2011/03/troubles-with-xml-in-jdk7-and-changing.html' title='Troubles with XML in JDK7 and changing to JDK6'/><author><name>Jan Volmut aka Qwei</name><uri>http://www.blogger.com/profile/06428806852379817758</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/-y0mYfcM0YS0/Tetm2F8rA1I/AAAAAAAAABo/oDV2d5CxejE/s220/forSocNetwork.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7465788861246650010.post-1398089582888486065</id><published>2011-03-28T12:20:00.000+01:00</published><updated>2011-03-28T12:20:45.799+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='info'/><title type='text'>First post</title><content type='html'>This is my first post to blog in my whole life. I have never use blogs until now. But world is changing and so do my opinions to life and so on. Well for now I just have to say welcome and excuse my english&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7465788861246650010-1398089582888486065?l=qwei.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://qwei.blogspot.com/feeds/1398089582888486065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://qwei.blogspot.com/2011/03/first-post.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/1398089582888486065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7465788861246650010/posts/default/1398089582888486065'/><link rel='alternate' type='text/html' href='http://qwei.blogspot.com/2011/03/first-post.html' title='First post'/><author><name>Jan Volmut aka Qwei</name><uri>http://www.blogger.com/profile/06428806852379817758</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/-y0mYfcM0YS0/Tetm2F8rA1I/AAAAAAAAABo/oDV2d5CxejE/s220/forSocNetwork.jpg'/></author><thr:total>1</thr:total></entry></feed>
