<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/blog/templates/schluetersde/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    <link href="http://schlueters.de/blog/feeds/atom10.xml" rel="self" title="Johannes Schlüter" type="application/atom+xml" />
    <link href="http://schlueters.de/blog/"                        rel="alternate"    title="Johannes Schlüter" type="text/html" />
    <link href="http://schlueters.de/blog/rss.php?version=2.0"     rel="alternate"    title="Johannes Schlüter" type="application/rss+xml" />
    <title type="html">Johannes Schlüter</title>
    <subtitle type="html">Always searching for Life, the Universe and Everything</subtitle>
    <icon>http://schlueters.de/blog/templates/schluetersde/img/s9y_banner_small.png</icon>
    <id>http://schlueters.de/blog/</id>
    <updated>2010-03-03T16:10:53Z</updated>
    <generator uri="http://www.s9y.org/" version="1.3">Serendipity 1.3 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://schlueters.de/blog/archives/127-Ob-ich-es-je-verstehen-werde.html" rel="alternate" title="Ob ich es je verstehen werde?" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-03-02T13:03:00Z</published>
        <updated>2010-03-03T16:10:53Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=127</wfw:comment>
    
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=127</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/7-Gesellschaft" label="Gesellschaft" term="Gesellschaft" />
    
        <id>http://schlueters.de/blog/archives/127-guid.html</id>
        <title type="html">Ob ich es je verstehen werde?</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Heute feiert <i title="Als ob es da nur eine einelne zentrale Community gäbe....">die</i> deutsche <i>Internet-Community</i> und ja das Urteil des BVerG ist zu begrüßen. Aber noch immer frage ich mich warum man einem Privatunternehmen deutlich mehr Daten freiwillig gibt.</p>

<p>Ich schrieb es ja <a href="http://schlueters.de/blog/archives/126-Dinge,-die-ich-nicht-verstehe-....html">zuvor</a> schon: Ich verstehe nicht wie Leute all Ihre Daten einem Unternehmen können und zugleich dagegen sind wenn der Staat ein <b>Bruchteil</b> der Daten per Gesetz bekommt. Ich weiß nicht ob Google heute selber irgendwas böses mit den Daten macht, nach allem was man so hört wohl nicht, aber zum einen haben staatliche Stellen schon heute Zugang zu den Daten bei Google zum anderen weiß man nicht was Google macht, wenn das Werbegeschäft mal was schlechter läuft, inzwischen haben die nen großen Stapel Mitarbeiter zu füttern und Aktionäre zufrieden zustellen.</p>

<p>Ja, Google gibt Daten an Behörden raus. In den USA ist das im Rahmen des <a href="http://de.wikipedia.org/wiki/USA_Patriot_Act">USA PATRIOT Act</a>  von 2001 geregelt und Eric Schmidt, CEO von Google, hat das ja unlängst in einem <a href="http://www.youtube.com/watch?v=A6e7wfDHzew">Interview betont</a>. In Deutschland haben wir zum Glück (noch?) kein vergleichbares Gesetz, dass Geheimdiensten und Polizeibehörden derart umfangreiche Rechte einräumt, wie dies im Patriot Act der Fall ist aber auch hier gibt  es Möglichkeiten, die zur Beschlagnahme von Daten von Google führen können .. oder auch sowas wie Geheimdienstliche Zusammenarbeit, die einen Zugriff deutscher Behörden nicht unmöglich machen (obei dann die Frage ist ob die CIA oder das BKA schlimmer ist <img src="http://schlueters.de/blog/templates/schluetersde/img/emoticons/wink.png" alt=";-)" style="display: inline; vertical-align: bottom;" class="emoticon" />)</p>

<p>Aber nur um nochmal zu erinnern was für Daten Google hat, dass sind ja nicht nur die Suchanfragen, die man mal so stellt sondern auch die Information welche Websites man so aufruft (Danke Google Ads und Google Analytics überall) das sind Mails die man so schreibt (und sei es nur weil der Empfänger GMail nutzt) das sind Informationen mit wem man wann so telefoniert (Android des angerufenen is ja an GMail&amp;Co. angebunden) In den USA sind das auch Inhalte von Mailboxnachrichten (die per Spracherkennung als Mail verschickt werden). Dank Picassa und Photoerkennung kennen die auch das Gesicht und Aufenthaltsorte (das is eigentlich der spannende Teil bei der Streetview-Diskussion - Google hat die unzensierten Bilder und automatische Gesichtserkennung ...) und noch viel mehr an Daten. Das kombiniert mit den Suchanfragen bei der Google Suche, der Produktsuche, Google Maps, .... gibt ein extrem detailliertes Persönlichkeitsbild. Nein. Ich verstehe nicht warum man sowas in einer einzigen Datenbank, die man nicht kontrolliert, haben wollen könnte. </p> 
            </div>
        </content>
        <dc:subject>bundesverfassungsgericht</dc:subject>
<dc:subject>daten frei</dc:subject>
<dc:subject>datenschutz</dc:subject>
<dc:subject>gmail</dc:subject>
<dc:subject>google</dc:subject>
<dc:subject>patriot act</dc:subject>
<dc:subject>privacy</dc:subject>
<dc:subject>recht und ordnung</dc:subject>
<dc:subject>urteilvorratsdatenspeicherung</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/126-Dinge,-die-ich-nicht-verstehe-....html" rel="alternate" title="Dinge, die ich nicht verstehe ..." />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-01-10T14:48:52Z</published>
        <updated>2010-01-17T12:58:06Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=126</wfw:comment>
    
        <slash:comments>10</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=126</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/7-Gesellschaft" label="Gesellschaft" term="Gesellschaft" />
    
        <id>http://schlueters.de/blog/archives/126-guid.html</id>
        <title type="html">Dinge, die ich nicht verstehe ...</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Ich verstehe vieles nicht, dazu gehört folgendes: Warum geben Leute alle ihre mails, ihre Kontaktdataten, ihre Kalendereinträge, ihre Dokumente an ein Unternehmen, dass, dank Werbung, weiß auf welchen Webseiten man sich rumtreibt, was einen interessiert? Warum kauft man ein Telefon, dass dem Unternehmen auch die genau Position mitteilt, Sprecherkennung auf zentralen Servern verarbeitet udn alle Einstellungen an den Hersteller übeträgt. Warum nutzt man einen Browser, dessen Hauptaufgabe es ist Daten zusammeln und an dne Hersteller zu liefern? Nein das verstehe ich nicht.</p><p>Aber was ich dabei ganz besonders nicht verstehe: Warum stören sich Leute an sowas wie Vorratsdatenspeicherung, aber nicht daran, dass ein Unternehmen, das in einem Land mit schwäscheren Datenschutzbestimmungen sitzt und auf Datensammlung und -auswertung spezialisiert ist, weit mehr Daten sammelt? - Nein das verstehe ich wirklich nicht.</p><p>Natürlich ist es nett, wenn sich die Daten zwischen Telefonbuch und Mail-Anwendung ohne Spezialanwendung synchronisieren, natürlcih ist es nett tolle Auswertungen über Website user zu haben, natürlich, ... aber zu welchem Preis?</p>
 
            </div>
        </content>
        <dc:subject>datenschutz</dc:subject>
<dc:subject>fragen</dc:subject>
<dc:subject>geheimnis</dc:subject>
<dc:subject>privat</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html" rel="alternate" title="Do not use PHP references" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-01-10T14:19:00Z</published>
        <updated>2010-01-14T21:01:33Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=125</wfw:comment>
    
        <slash:comments>19</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=125</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/125-guid.html</id>
        <title type="html">Do not use PHP references</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Last year I spoke at eight conferences and attended a few more multiple times at most of them I found myself in discussions about references and PHP as many users seem to have wrong understandings about them. Before going to deep into the subject let's start with a quick reminder what references are and clear some confusion about objects which are &quot;passed by reference.&quot;</p>

<p>References are a way to have multiple variables referencing the same variable container using different names -- so whatever name you're using an operation on that variable will always have an effect on the others.</p>

<p>Let's look into it with some code to make this all clearer. For a start we simply do a regular assignment from one variable to the other and change it:</p>

<blockquote><pre>&lt;?php
$a = 23;
$b = $a;
$b = 42;
var_dump($a);
var_dump($b);
?&gt;
</pre></blockquote>

<p>This script will tell us that <i>$a</i> still is <i>23</i> and <i>$b</i> equals <i>42</i>. So what happened here is that we got a copy (more on what actually happened later...) now let's do the same with a reference:</p>

<blockquote><pre>&lt;?php
$a = 23;
$b = &amp;$a;
$b = 42;
var_dump($a);
var_dump($b);
?&gt;
</pre></blockquote>

<p>Now suddenly <i>$a</i> changes to <i>42</i>, too. In fact there is no difference between <i>$a</i> and <i>$b</i> and both are using the same internal variable container (aka. <i>zval</i>). The only way to separate these two is by invalidating one of the variables using <i>unset()</i>.</p>

<p>References in PHP can't only be created in regular assignments but also for function parameters or return values:</p>

<blockquote><pre>&lt;?php
function &amp;foo(&amp;$param) {
    $param = 42;
    return $param;
}

$a = 23;
echo &quot;\$a before calling foo(): $a\n&quot;;
$b = foo($a);
echo &quot;\$a after the call to foo(): $a\n&quot;;
$b = 23;
echo &quot;\$a after touching the returned variable: $a\n&quot;;
?&gt;
</pre></blockquote>

<p>The result from this is, well what do you expect? Right - it looks like this:</p>

<blockquote><pre>$a before calling foo(): 23
$a after the call to foo(): 42
$a after touching the returned variable: 42
</pre></blockquote>

<p>So we initialize a variable, pass it to a function as referenced parameter. The function changes it and it has the new value. The function returns the same variable, we change the returned variable and the original value ... wait it didn't change!? - Yes references are mean. What happened is the following: The function returned a reference, referencing the same <i>zval</i> as <i>$a</i> and the <i>=</i> assignment operator creates a copy of it.</p>

<p>To fix this we have to add one <i>&amp;</i> more:</p>

<blockquote><pre>$b = &amp;foo($a);
</pre></blockquote>

<p>Then the result is what one would expect:</p>

<blockquote><pre>$a before calling foo(): 23
$a after the call to foo(): 42
$a after touching the returned value: 23
</pre></blockquote>

<p>Summary so far: PHP references are alias to the same variable and properly using them can be hard. For details on the reference counting, whichisthebase for this, check the <a href="http://php.net/features.gc.refcounting-basics">according section in the manual</a>.</p>

<p>When PHP 5 came to live one of the big changes was how objects were handled. The general explanation is something like this:</p>

<blockquote>
  In PHP 4 objects are treated like other variables so when using them
  as function parameters or doing assignments they are copied. In PHP 5
  they are always passed by reference.
</blockquote>

<p>Which isn't entirely correct. The issue to solve was about object oriented patterns: Objects are passed as parameters to some function or method, this function sends a signal to the object (aka calls a method) which then might change the object's state (aka. its properties). For this to work the object has to be the same. PHP 4 OO users now always passed explicit references, which is, as we saw above, tricky to do correctly. To make this nicer in PHP 5 an object storage which is independent from the variable container was introduced. So inside the variable we don't store the whole object anymore (which basically means the properties table plus class information) but a reference to an object inside an object storage - so if we create a copy of the variable we don't copy the object but this reference (or: handle) so it feels like an reference, but be aware it is no reference but a different concept. The difference can be seen by directly changing the variable:</p>

<blockquote><pre>&lt;?php
// create an object and a copy as well as a reference to the variable
$a = new stdclass;
$b = $a;
$c = &amp;$a;

// Do something with the object
$a-&gt;foo = 42;
var_dump($a-&gt;foo);
var_dump($b-&gt;foo);
var_dump($c-&gt;foo);

// Now change the variable itself
$a = 42;
var_dump($a);
var_dump($b);
var_dump($c);
?&gt;
</pre></blockquote>

<p>When running this you can see that the access to the property really affects the <i>copy</i>, too but in the last assignment you can see the difference to an reference as <i>$b</i> is not affected by it. This is the behavior most (all?) people with OO experience expect.</p>

<p>So OO was one valid reason for using references, but as PHP 4 is dead for over one year now old code using this should really cleaned up!</p>

<p>Another reason people use reference is since they think it makes the code faster. But this is wrong. It is even worse: References mostly make the code slower!</p>

<p>Yes, references often make the code slower - Sorry, I just had to repeat this to make it clear.</p>

<p>When coming from other languages from other languages people read in style guides that passing copies of large structures or strings should be avoided as creating a copy takes time. In some environments complex structures have to be passed as pointers, which is a fundamentally different model from references, and people take this to PHP references. But PHP is not that other language but PHP with PHP's runtime and in PHP we do copy-on-write.</p>

<p>With copy-on-write we don't copy on an assignment or function call but just note that there are multiple independent variables pointing at one and the same variable container and only if there is a write operation we separate the variable, which is written to, from the others. This means that even so a variable looks like a copy it's in fact no copy and the function call takes no penalty do to big parameters. The problem with references now is that they disable the copy-on-write mechanism so any following non-reference assignment using this variable will create an immediate copy. This in itself won't be bad - you could simply use references everywhere, well not really: PHP is built around the copy-on-write availability so most internal functions expect copies.</p>

<p>Somewhere I found code which something looks like this:</p>

<blockquote><pre>&lt;?php
function foo(&amp;$data) {
    for ($i = 0; $i &lt; strlen($data); $i++) {
        do_something($data{$i});
    }
}

$string = &quot;... looooong string with lots of data .....&quot;;
foo(string);
?&gt;
</pre></blockquote>

<p>Now the first issue with this code is obvious: It is calling <i>strlen()</i> in a loop for each iteration while the length is calculated. So that's <i>strlen($data)</i> function calls while a single one would be enough. Now with <i>strlen()</i> it won't be too bad as, unlike in a language like C, strings in PHP directly carry the length so no calculation is needed, in general. But now in this case the developer tried to be smart and save time by passing a reference. But well, <i>strlen()</i> expects a copy. copy-on-write can't be done on references so <i>$data</i> will be copied for calling <i>strlen()</i>, <i>strlen()</i> will do an absolutely simple operation - in fact <i>strlen()</i> is one of the most trivial functions in PHP - and the copy will be destroyed immediately.</p>

<p>If no reference is being used no copy is needed which makes the code way faster and even if <i>strlen()</i> would take the reference you wouldn't have won anything.</p>

<p>Summary so far: </p>
<ul>
<li>Do not use references for OO but get ridof PHP 4 legacy.</li>
<li>Do not use references for performance.</li>
</ul>

<p>Now a third thing which is done with references is bad API design by returning via reference parameters. The issue here is, again, that people forget that PHP is PHP and not another language.</p>

<p>In PHP you can return multiple types from the same function - so if the function was successful you could return a string and a boolean <i>false</i> in case of an error. PHP also allows to return complex structures like arrays and objects, so if multiple things are to be returned they can be packed together. Additionally there are exceptions as a way to return from a function.</p>

<p>Using referenced parameters is a bad thing, additionally to the fact that references are bad and cause performance penalties using references in this way makes code hard to maintain. Having such a function call:</p>

<blockquote><pre>  do_something($var);
</pre></blockquote>

<p>Would you expect that $var will change? - No. But if <i>do_something()</i> takes it as a reference it could happen.</p>

<p>Another problem with such APIs is that function calls can't be nested but you always have to use a temporary variable, now nesting function calls can also reduce readability, but there are enough situations where nesting makes the code clearer.</p>

<p>My personal favorite example for a bad design decision in regards to references is PHP's own <i>sort()</i> function. <i>sort()</i> takes an array as reference parameter which will be returned in sorted order by reference. It would be way nicer to return the sorted array as regular return value. The reason for this is history: <i>sort()</i> is older than copy-on-write. Copy-on write was introduced with PHP 4, while sort() is way older and from times before PHP really was its own language but a shortcut to do some things in the Web.</p>

<p>To sum it up: References in PHP are bad. Do not use them. They hurt and will just mess with things and do not expect to be able to outsmart the engine with references!</p> 
            </div>
        </content>
        <dc:subject>api design</dc:subject>
<dc:subject>best practice</dc:subject>
<dc:subject>guidlines</dc:subject>
<dc:subject>oop</dc:subject>
<dc:subject>performance</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php 4</dc:subject>
<dc:subject>php coding</dc:subject>
<dc:subject>php oo</dc:subject>
<dc:subject>planet php</dc:subject>
<dc:subject>references</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/124-Class-posing-and-overloading-the-new-operator.html" rel="alternate" title="Class posing and overloading the &quot;new&quot; operator" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-01-01T18:39:00Z</published>
        <updated>2010-01-01T21:08:31Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=124</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=124</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/124-guid.html</id>
        <title type="html">Class posing and overloading the &quot;new&quot; operator</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Two years ago at some conference I had a conversation with <a href="http://www.sebastian-bergmann.de">Sebastian</a> about the need for a way to overload the <a href="http://php.net/new"><i>new</i></a> operator in PHP so, probably, bad designed code can be tested more easily by replacing specific classes with mocks. On the train ride home -- I like coding on a train without the disturbing Internet -- I came up with a proof-of-concept extension for PHP and sent it to Sebastian.</p>
<p>Then we more or less forgot about it or did other things until a few days ago where both, Sebastian and I, independently remembered it. Sebastian then pushed the code as part of a new <i>test_helpers</i> extension with some documentation <a href="http://github.com/sebastianbergmann/php-test-helpers/">to github</a> and I fixed some bugs in it. The aim of the extension is to collect functionality which might be beneficial for phpUnit and other test scenarios but which should never reach a production environment.</p>
<p>Currently only the <i>new</i> overloading is part of this extension. A simple example might look like this:</p>
<blockquote>
<pre>&lt;?php
class Foo {}
class Bar {}

function callback($className) {
    if ($className == 'Foo') {
        $className = 'Bar';
    }

    return $className;
}

var_dump(get_class(new Foo));

set_new_overload('callback');
var_dump(get_class(new Foo));
?&gt;
</pre>
</blockquote>

<p>Which will print</p>

<blockquote>
<pre>string(3) &quot;Foo&quot;
string(3) &quot;Bar&quot;</pre>
</blockquote>

<p>Today Sebastian was brave and released it as 1.0.0 on <a href="http://pear.phpunit.de">phpUnit's PEAR channel</a>. Please refer to the <a href="http://github.com/johannes/php-test-helpers/blob/master/README.markdown">README</a> for further information.</p> 
            </div>
        </content>
        <dc:subject>new</dc:subject>
<dc:subject>overloading</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php extensions</dc:subject>
<dc:subject>qa</dc:subject>
<dc:subject>testing</dc:subject>
<dc:subject>test_helpers</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/123-Shooting-with-Crossbows-into-Zones.html" rel="alternate" title="Shooting with Crossbows into Zones" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-11-28T15:28:00Z</published>
        <updated>2009-11-28T15:44:41Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=123</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=123</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/2-Software" label="Software" term="Software" />
    
        <id>http://schlueters.de/blog/archives/123-guid.html</id>
        <title type="html">Shooting with Crossbows into Zones</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Ok, so this site (and some other stuff) is <a href="http://schlueters.de/blog/archives/122-Now-running-on-OpenSolaris.html">now running on OpenSolaris</a>. The previous previous article was mostly a test entry for me to see whether the DNS update was through but as some people wonder why I'm using <i>this system</i> that &quot;fails while trying to copy Linux&quot; I decided to discuss some of the reasons in more detail.</p><p>Some people already know that my main system meanwhile runs <a href="http://www.opensolaris.org/">OpenSolaris</a>. The reason there is <a href="http://schlueters.de/blog/plugin/tag/DTrace">DTrace</a> - a great way to see what the system, from the kernel, over userspaces programs, into a VM like the JVM or PHP's Zend VM, ... is doing which is a big help while debugging and developing applications. Even though DTrace is meant to do such analysis on live machines this wasn't the main reason for this choice on the server. For the server I actually didn't plan a change, ok, the old Linux box wasn't maintained well but it worked good enough for the few things it does, but then <a href="http://blog.experimentalworks.net/">David</a> came along and had the idea to share a server so I started thinking about dropping the old contract and getting a new machine for us both - and possible some other friends. And there we find the actual reasons for the OS choice:</p><h4>Zones</h4><p>So we were planing to share a box as both of us are doing Web/PHP-related stuff it was clear that it's likely that both of us would might need special versions and configurations of some software components which will then conflict with each other. Additionally I want to be able to do a <i>killall apache</i> in case I configured something wrong and I don't want the others to be affected too much while configuring my web servers as I need/want them. The obious solution these days? - Virtualization.</p><p>Now virtualization comes in many flavors. The simple one most people know is Desktop Virtualization, so you take a software like <a href="http://www.virtualbox.org/">VirtualBox</a>, which is running as a regular userspace application and holds a complete operating stack. In there one has a kernel of the virtualized system which thinks it's running directly on physical hardware. The big benefit is that one can run any operating system in the VM but also has negative effects in areas like disk buffers (the virtualized and the host kernel buffer independently) or overall process scheduling (the VM is scheduled by the host and then schedules itself again..) or syscalls (an application running in the VM does a syscall to the VM's kernel which then calls a Hypervisor-provided hardware emulation function which then triggers a syscall on the hostsystem)</p><p>Another approach is Operating System Virtualization like Solaris Zones. Here the operating system handles the virtualiztion. With zones this works in a way were one has a single kernel and multiple userland instances. By this one has one kernel with one scheduler (ok, Solaris allows using different schedulers and so on - let's ignore this and look at the default) and one disk IO layer. Inside a Zone one has Zone-specific userland with service management an own network device (see more on this below), an own user database (/etc/passwd, LDAP, ...) and so on. But as of the syscall interface it all runs on one kernel which also means that all processes are handled equally by the kernel (unless configured otherwise)</p><p>The result of using Solaris Zones is that one has a lightweight isolation of independent userland environments. Now as said the virtualisation has one boundary at the syscall layer, so the userland has to be Solaris - one thinks. But that's not true: There are Branded Zones which emulate another syscall interface,by that one can run a Linux userland on a Solaris kernel so Linux-only apps benefit from stuff like ZFS and DTrace - but that's not relevant for me here.</p><p>So to summarize: Zones are great for lightweight isolation (and other stuff)</p><h4>Crossbow</h4><p>Now I was mentioning that each Zone can have it's own network interface assigned.This is nice if you have a box with many network devices - now a typical server you get as a root-server for little money usually has just one. Now what you traditionally can do is assigning multiple IPs to that device and then use the single device shared over multiple zones. That works but is inconvenient as you can't really check the status (which device/zone is producing how much traffic?) or add bandwidth limitations (I want to be able to reduce one zones bandwidth in case an article is <i>slashdotted</i> without going to deep into everything to keep other parts of the system running) and additionally IP addresses are limited and I don't want all zones to be publicly accessible - for instance my MySQL zone can't be reached from the outside.</p><p>Now crossbow - that's the name of the Solaris network virtualization layer introduced with OpenSolaris 2009.06 - for me always was a <i>so what</i> thing till I started using it. Well yes you can create virtual switches and virtual network interfaces. So what? Well combined with zones I can achieve what I described in the above paragraph.</p><p>So let's build a network:</p><blockquote><p>dladm create-etherstub mystub0<br />dladm create-vnic -l mystub0 vnic0<br />dladm create-vnic -l mystub0 vinc1</p></blockquote><p>That's all that's needed to create an internal ethernet with two devices. Next step is to assign them to zones and configure IP for this network. In my current setup I have a zone for this web site and one zone for the MySQL server. The MySQL zone has a vnic for an internal network, the web-zone has two vnics - one is used for the internal network and the second is configured to work on top of the physical networking device so it can talk to the outside using its own public IP address. For limiting resources and stuff there's the flowadm tool for simple access to control network resource limits or service priorities (ssh connections have higher priorities so the system can be controlled in case the network is busy)</p><p>And even for me, who tries to stay above the TCP layer, this is quite trivial to setup.</p><h4>ZFS</h4><p>Now one of the most cited features of Solaris is the zfs filesystem. While zfs is more than just a filesystem - it's a combination of volume manager, raid controller and other related things. The key feature there for me is snapshotting: zfs is using a copy on write mechanism so zfs can create snapshot which in itself has barely no costs. Only if data is changed a new block is being written and the old one is kept untouched by that the snapshots costs only the space the difference needs. Additionally this allows clones so one gets a copy of a directory and it will cost space only if data is changed - that's of special interest with zones. As said each zone is it's own userspace system. By using zfs clones they share the same blocks on disk. Really useful. In the next version this will even be better thanks to deduplication in zfs ...</p><h4>Problems</h4><p>Coming from Linux there are - of course - different problems, as I'm using OpenSolaris on other boxes for sometime now I'm used to many administration tools but I learn new things every time i work on the system.</p><p>A bit more problematic is that the main OpenSolaris package repository doesn't offer as much software as typical linux distributions, but for most software packages can be found in other repositories, too. This is a bit annoying but as one can see the growth and has access to above mentioned features this is no big problem - especially on a server where most of the tools exist for Solaris, too.</p><p>Oh, and for the German speakers: David and I discussed some experience while installing the server in the  <a href="http://www.systemhelden.com/?p=254">latest HELDENFunk podcast</a>.</p> 
            </div>
        </content>
        <dc:subject>crossbow</dc:subject>
<dc:subject>dtrace</dc:subject>
<dc:subject>opensolaris</dc:subject>
<dc:subject>server</dc:subject>
<dc:subject>solaris</dc:subject>
<dc:subject>solaris zones</dc:subject>
<dc:subject>virtualization</dc:subject>
<dc:subject>zones</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/122-Now-running-on-OpenSolaris.html" rel="alternate" title="Now running on OpenSolaris" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-11-24T22:28:56Z</published>
        <updated>2009-11-28T15:37:50Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=122</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=122</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/1-General" label="General" term="General" />
    
        <id>http://schlueters.de/blog/archives/122-guid.html</id>
        <title type="html">Now running on OpenSolaris</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<a href="http://opensolaris.org" class="serendipity_image_link"><!-- s9ymdb:51 --><img width="125" height="125" src="http://schlueters.de/blog/uploads/logos/powered-by-opensolaris1.gif" style="border: 0px none ; float: right; padding-left: 5px; padding-right: 5px;" class="serendipity_image_right" /></a>
<p>
So, this website moved. It isn't the citizen of a Linux box anymore but is running inside a zone on an OpenSolaris host. The only non-default software powering this server I compiled myself is a current svn snapshot of PHP 5.3.2-dev. Let's see if I can keep this system clean or whether it becomes such a mess as the old Linux box. For now I'm happy about the isolation using zones, snapshots with ZFS before playing around and DTrace in case something goes wrong <img src="http://schlueters.de/blog/templates/schluetersde/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /></p> 
            </div>
        </content>
        <dc:subject>blog</dc:subject>
<dc:subject>dtrace</dc:subject>
<dc:subject>linux</dc:subject>
<dc:subject>opensolaris</dc:subject>
<dc:subject>solaris</dc:subject>
<dc:subject>zfs</dc:subject>
<dc:subject>zones</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/121-PHP-5.3.1RC2.html" rel="alternate" title="PHP 5.3.1RC2" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-10-21T20:49:31Z</published>
        <updated>2009-10-21T20:59:35Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=121</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=121</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/121-guid.html</id>
        <title type="html">PHP 5.3.1RC2</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Just a quick heads-up: After quite some time from RC1 PHP 5.3.1RC2 has finally been packaged and released. The <a href="http://bugs.php.net">PHP bug tracker</a> is welcoming reports about issues, I also welcome positive feedback.</p><p>Downloads:</p><ul><li>Source:<br /><a href="http://downloads.php.net/johannes/php-5.3.1RC2.tar.bz2">http://downloads.php.net/johannes/php-5.3.1RC2.tar.bz2</a><br /><a href="http://downloads.php.net/johannes/php-5.3.1RC2.tar.gz">http://downloads.php.net/johannes/php-5.3.1RC2.tar.gz</a></li><li>Windows binaries:<br /><a href="http://windows.php.net/qa/">http://windows.php.net/qa/</a></li></ul><p>(This release candidate is not meant to be used in production systems, wait for the final release for that but please test this version)<a href="http://windows.php.net/qa/"></a></p> 
            </div>
        </content>
        <dc:subject>php releases</dc:subject>
<dc:subject>php53</dc:subject>
<dc:subject>phpqa</dc:subject>
<dc:subject>planet php</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/120-Ich-weiss-was-Du-Sonntag-machst.html" rel="alternate" title="Ich weiß was Du Sonntag machst" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-09-25T16:25:26Z</published>
        <updated>2009-09-25T16:39:58Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=120</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=120</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/7-Gesellschaft" label="Gesellschaft" term="Gesellschaft" />
    
        <id>http://schlueters.de/blog/archives/120-guid.html</id>
        <title type="html">Ich weiß was Du Sonntag machst</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>... das hoffe ich zumindest <img src="http://schlueters.de/blog/templates/schluetersde/img/emoticons/wink.png" alt=";-)" style="display: inline; vertical-align: bottom;" class="emoticon" /></p>
<p>Diesen Sonntag ist Bundestagswahl, hingehen, zwei Kreuzchen machen, fertig. (naja, gut, in Brandenburg und Schleswig-Holstein darf man etwas mehr Kreuzen) Dabei beachten: Es gibt mehr als 5 Parteien, d.h. auch wenn man die &quot;etablierten&quot; Parteien nicht mag gibt es jemanden den man wählen kann. Es kommt auf jede Stimme an! - Wer nicht wählt soll sich am ende auch nicht beschweren.</p>
<p>Seit einiger Zeit habe ich ja meine eigene <a href="http://apps.facebook.com/wahltipp/">Wahlumfrage via Facebook</a>. Sehr spannende <a href="http://apps.facebook.com/wahltipp/results.php">Ergebnisse</a> da, aber auch da hoffe ich noch auf mehr Tipps um die Prognose genauer zu machen.</p> 
            </div>
        </content>
        <dc:subject>bundestagswahl</dc:subject>
<dc:subject>facebook</dc:subject>
<dc:subject>politik</dc:subject>
<dc:subject>wahl2009</dc:subject>
<dc:subject>wahltipp</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/119-Keine-drei-Wochen-mehr.html" rel="alternate" title="Keine drei Wochen mehr" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-09-06T22:25:33Z</published>
        <updated>2009-09-09T09:16:55Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=119</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=119</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/7-Gesellschaft" label="Gesellschaft" term="Gesellschaft" />
    
        <id>http://schlueters.de/blog/archives/119-guid.html</id>
        <title type="html">Keine drei Wochen mehr</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<ps>In weniger als drei Wochen ist also Bundestagswahl. Und alle Parteien haben die &quot;heiße&quot; Phase des Wahlkampfes eingeläutet. Sogar die CDU mit der Kanzlerin sind ja jetzt etwas aufgewacht, es wird also definitiv zeit sich mit dem Thema zu beschäftigen, denn wählen, das is klar, muss man -- wer sein Wahlrecht nicht nutzt braucht sich nachher nicht beschweren. Das auch die einzelne Stimme zählt haben die Jungs vom Topf auch schön <a href="http://www.youtube.com/watch?v=W96c9uVlhlE">musikalisch unterlegt</a>. Und dieses Jahr wird das wohl auch etwas spannender als oftmals zuvor: Die Umfrageinstitute haben bei den letzten Landtagswahlen mal wieder gezeigt wieviel die Umfragen wert sind und auch sowas wie die Parteien werden kaum berücksichtigt, mit etwas Geschick und Glück haben die jedoch ein Potential für eine Überraschung und auch die Etablierung der Linken im Westen führt schnell zu unklareren Mehrheiten bei denen jede Stimme zählt.<p>
<img src="http://chart.apis.google.com/chart?chs=236x120&chd=t:14.65,23.58,7.72,8.34,10.12,8.87,23.19,3.49&cht=p&chl=GR%C3%9CNE|CDU|CSU|DIE+LINKE|FDP|PIRATEN|SPD|Sonstige&chco=00FF00|000000|111111|bb0000|ffff00|cc7700|FF0000|dddddd" style="width: 236px; height: 120px; float: right;" />
</p><p>Um da mal etwas Licht und eine andere Perspektive zu bekommen habe ich vor kurzem eine kleine Anwendung bei Facebook gebaut, den <a href="http://apps.facebook.com/wahltipp/results.php">Wahltipp</a>. Im Gegensatz zur &quot;Sonntagsfrage&quot; frage ich nicht nach der eigenen Wahl sondern lasse auf das Ergebnis tippen in der Hoffnung, dass da kollektiv eine gute Prognose raus kommt. Am Ende kommen ein paar Ergebnisse in Tabellen- und Grafikform raus. Bin ja mal gespannt wie das am Ende passt. Über Leute die <a href="http://apps.facebook.com/wahltipp/results.php">mit machen</a> freue ich mich. Ja,man muss Facebook User sein, so muss ich nur ne von Facebook erzeugte Benutzer ID speichern und kann auf eigene Userverwaltung verzichten und muss deutlich weniger persönliche Daten speicherm...</p></ps> 
            </div>
        </content>
        <dc:subject>bundestagswahl</dc:subject>
<dc:subject>cdu</dc:subject>
<dc:subject>demokratie</dc:subject>
<dc:subject>facebook</dc:subject>
<dc:subject>merkel</dc:subject>
<dc:subject>piraten</dc:subject>
<dc:subject>politik</dc:subject>
<dc:subject>superwahljahr</dc:subject>
<dc:subject>umfragen</dc:subject>
<dc:subject>wahl2009</dc:subject>
<dc:subject>wahltipp</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/118-Searching-through-archive-files.html" rel="alternate" title="Searching through archive files" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-09-03T10:35:00Z</published>
        <updated>2009-09-02T17:28:13Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=118</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=118</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/118-guid.html</id>
        <title type="html">Searching through archive files</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>To learn a bit about PHP Gtk I'm working on some <a href="http://johannes.github.com/php-explorer/">small GUI application</a> to read the PHP manual, quite rough and the sole purpose is to play with PHP Gtk. People who know me know that I really love iterators in PHP so obviously this app is using iterators, too. In this post I want to share an example where iterators are really useful:</p>
<p>As said the app is about browsing the PHP manual. The manual is provided as <i>tar.gz</i> to the app and I wanted to have a fulltext search. For accessing the <i>tar.gz</i> content I'm using <i>phar</i>. Yes, <i>phar</i> is not only for <i>phar</i> files but can work on different kinds of archives (tar.gz, tar.bz2, zip), too.</p><p>So that's my search implementation:</p>
<blockquote>
<pre>class FullTextSearch extends FilterIterator {
    protected $needle;
 
    public function __construct(PharData $archive, $needle) {
        $flags = RecursiveIteratorIterator::LEAVES_ONLY;
        $it = new RecursiveIteratorIterator($archive, $flags);
        parent::__construct($it);
 
        $this-&gt;needle = $needle;
    }
 
    public function accept() {
        $current = $this-&gt;current();
        // This is not 100% perfect but should be good enough for this case:
        if (strpos($current-&gt;getFilename(), '.htm') === false) {
            return false;
        }
 
         // This is bad for larger files ...
         $content = file_get_contents($current-&gt;getPathname());

         return strpos($content, $this-&gt;needle) !== false;
    }
}

$needle = 'search';
$archive = new PharData('php_manual_en.tar.gz');

$search = new FullTextSearch($archive, $needle);
foreach ($search as $filename =&gt; $fileobject) {
    echo &quot;Found in $filename.\n&quot;;
}
</pre>
</blockquote>
<p>The code has some places marked which might need some improvements for general purpose but shows how nice iterator-based solutions can be.</p>
<p>If you aren't used to iterators you most likely wonder what's going on, so let's look into it:</p>
<p>First we need some basic knowledge. An <i>Iterator</i> in PHP is, basically, an object that can be used in <i>foreach</i> statements and does something - an <i>ArrayIterator</i>, for instance, walks over an array returning all the array elements. Now <i>PharData</i> objects are <i>RecursiveDirectoryIterators</i>. This means you can put the phar data object into a <i>foreach</i> statement and you'll get a list of all files - oh wait it's not that easy. Actually you will receive only the root elements. Confused? - On the one hand I said it's recursive but on the other hand it only returns the root elements? - Well having a <i>RecursiveIterator</i> means that the object provides methods to check whether the current element has children and can provide an <i>Iterator</i> to iterate over these children. <i>foreach</i> won't call these methods - that's the job of the <i>RecursiveIteratorIterator</i> (<i>RII</i>). The <i>RII</i> is a so-called outer iterator which means it iterates over the elements of another iterator. In this case it will walk over the files in the archive and will, for every file, check whether it is a directory. In case the current entry is an directory it will work, recursively, in that directory till all files were returned.</p>
<p>Having this basic knowledge we could write code like this:</p>
<blockquote>
<pre>$it = new RecursiveIteratorIterator($archive);
foreach ($it as $filename =&gt; $fileobject) {
    echo $filename.&quot;\n&quot;;
}
</pre>
</blockquote>
<p>This gives use a list of all files and directories in the archive. The next thing I'm having in the first snippet is a <i>FilterIterator</i>. A <i>FilterIterator</i> is - again - an outer iterator doing exactly what the name says: It filters the elements from it's inner iterator. For that it calls the accept() when stepping to the next element. If accept() returns <i>true</i> the element is given to the caller (being the <i>foreach</i> statement or another iterator) if it returns false the element is ignored and the <i>FilterIterator</i> checks the next element. So in this case I only care about elements containing the needle from my search.</p>
<p>With all this there's just one little thing left in the code: Treating directories like file and searching through them won't work and in this case I absolutely don't care about the directories themselves so I ask the <i>RecursiveIteratorIterator</i> to step over the directory handles and directly go to the children.</p> 
            </div>
        </content>
        <dc:subject>fulltext search</dc:subject>
<dc:subject>phar</dc:subject>
<dc:subject>php explorer</dc:subject>
<dc:subject>php gtk</dc:subject>
<dc:subject>php.iterator</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/117-Code-and-human-languages.html" rel="alternate" title="Code and human languages" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-08-03T17:28:00Z</published>
        <updated>2009-08-07T08:26:49Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=117</wfw:comment>
    
        <slash:comments>6</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=117</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/117-guid.html</id>
        <title type="html">Code and human languages</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>In a <a href="http://schlueters.de/blog/archives/116-Unicode-identifiers.html">previous blog</a> post I mentioned the possibility for using non ASCII characters as part of identifiers. Nils Langner, who runs the German &quot;PHP hates me (but that's ok)&quot; blog, <a href="http://www.phphatesme.com/blog/allgemein/domanenspezifische-funktionsnamen/">then wondered</a> whether it makes sense to use German (in his case) terms for identifiers in code in the comments it was also discussed what language is best to be used in comments.</p>
<p>The argument for using only English is simple: Every developer should know at least basic English and using English helps when either outsourcing, opensourcing or reaching new markets.</p><p>Now there are arguments against English, too, one is that not all developers are able of using English properly so reading and writing comments is more difficult for them - now you don't have to write long prosaic texts in comments, but still ...</p><p>The other argument goes by domain-specific terminology. In some cases - for instance when bound to legal environments - such terms can't be translated properly. For instance when dealing with financial data accounting by US-GAAP differs in many parts from the German accounting rules: For some positions you find translations which have the same meaning but are calculated slightly different so using the English term would imply the values would be calculated by the US rules (sorry British folks for this example - I have no idea about the British terminology and accounting rules, but have basic understanding of German rules and US-GAAP <img src="http://schlueters.de/blog/templates/schluetersde/img/emoticons/wink.png" alt=";-)" style="display: inline; vertical-align: bottom;" class="emoticon" />). Ignoring this problem you still have to consider that you'd still talk German to your customer so the customer would use German terminology and you have to keep a dictionary for these terms which is a pain for everybody involved.</p><p>So now one could use mostly English with some local terms which gives a nice mixture (&quot;function getEigenkapitalrendite()&quot;) or invent complete new terminology (&quot;function erhalteEigenkapitalrendite()&quot;) which is stupid in comments, too (&quot;The Eigenkapitalrendite is depending on the Gewinn and the Eigenkapital&quot;) ...</p><p>Now I'm in the &quot;lucky&quot; position that most things I do these days are either done for some American company or a popular world wide used open source project and is mostly about stuff where the typical terminology is English so I can use my bad English everywhere - but I'm curious what others are doing and what others think.</p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>comments</dc:subject>
<dc:subject>english</dc:subject>
<dc:subject>german</dc:subject>
<dc:subject>language</dc:subject>
<dc:subject>php</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/116-Unicode-identifiers.html" rel="alternate" title="Unicode identifiers" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-07-22T22:33:37Z</published>
        <updated>2009-07-25T00:04:31Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=116</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=116</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/116-guid.html</id>
        <title type="html">Unicode identifiers</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>When I see people talking about Unicode and PHP 6 I often see them mentioning one fact as a <i>big</i> change: PHP 6 allows (mostly any) arbitrary Unicode character as (part of an) identifier. So you can have code like this:</p>
<blockquote>
<code>function <a href="http://translate.google.de/translate_s?hl=en&clss=&q=%E6%96%B0%E6%97%A5%E6%9C%AC%E7%9F%B3%E6%B2%B9&tq=&sl=en&tl=ja">新日本石油</a>() {<br />    echo &quot;Let's hope this isn't an offensive function name... &quot;;<br />    echo &quot;it's copied from some news site&quot;;<br />}<br />
<br />
新日本石油();</code>
</blockquote>
<p>Well yes, that's funny, at first but serves a purpose: Consider you have an application tied to an environment with a special terminology, then translating this terms to English might be extremely confusing (especially as programmers often don't really know the correct terminology of that domain) and it's good to call the thing by it's name - while that can be quite complicated, too, in a previous job we had such a case and often used the German terms which produced quite funny names for getters and setters which didn't satisfy us ... but that's not what I wanted to talk about.</p><p>The purpose of this were some bad news: That's nothing new. The relevant scanner rule hasn't changed since 4.0 - the only change is that PHP 6 doesn't treat it as random set of bytes anymore but knows about Unicode codepoints and interprets is as such.</p><p>Out of interest I did some little digging into the PHP repository's history:</p>
<blockquote>
<code>
$ svn annotate trunk/Zend/zend_language_scanner.l<br />
...<br />
 34779       zeev LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*<br />
...<br />
$  svn log -r 34779<br />
------------------------------------------------------------------------<br />
<a href="http://svn.php.net/viewvc?view=revision&revision=34779">r34779</a> | zeev | 2000-10-29 15:35:34 +0100 (Sun, 29 Oct 2000) | 2 lines<br />
<br />
Unify the names of these last 3 files...<br />
<br />
------------------------------------------------------------------------<br />
</code></blockquote>
<p>The result? - The rule, as it is in PHP 6 wasn't changed since 2000, really nothing new there with PHP 6, and even then the only change was that the scanner file was renamed...</p> 
            </div>
        </content>
        <dc:subject>japanese</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php 6</dc:subject>
<dc:subject>php svn</dc:subject>
<dc:subject>rumors</dc:subject>
<dc:subject>svn</dc:subject>
<dc:subject>unicode</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/115-PHP-5.3-Release-Party.html" rel="alternate" title="PHP 5.3 Release Party" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-07-14T11:19:08Z</published>
        <updated>2009-07-14T11:36:04Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=115</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=115</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/115-guid.html</id>
        <title type="html">PHP 5.3 Release Party</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>In my <a href="http://schlueters.de/blog/archives/113-PHP-5.3-is-released.html">blog post</a> for the 5.3 release I already mentioned it and some others posted it, too: We're planning a release party in Munich, currently we have around 60 people who registered. That's the official announcement:</p>

<blockquote>
We like to invite you to the <strong>PHP 5.3 release party </strong> on Friday, the <strong>17th of July</strong> in Munich.
The release party offers a chance to talk to other PHP enthusiasts and enjoy that PHP is alive and kicking. If you just can't resist a decent barbecue together with some beer and other drinks you are also welcomed.

<br /><p /><div>
<img width="100" height="100" src="http://www.waldwirtschaft.de/bilddaten/grundelemente/siegel.jpg" style="float: left; padding-left: 5px; padding-right: 5px;" />
The happening will take place at the <a href="http://www.waldwirtschaft.de" title="Waldwirtschaft"><strong>Waldwirtschaft</strong></a> beer garden irrespective of the weather. 
We will meet at <strong>19:00 o'clock</strong> - open end.

<br />
<em>The location is famous for its huge beer garden (2,500 available seats, a children’s playground) and its typical Bavarian but also international food. On sunny weather you may even enjoy live-music and listen to the sounds of Jazz, Blues, Swing or Dixi.</em>
</div>

<br />
Catering will be provided and as a special delicacy you may enjoy a suckling pig!

<br />
<br />
If you like to join the event please register at <a href="http://www.phpugmunich.org/dokuwiki/php_release_party" title="PHPUG Munich">PHPUG-Munich Wiki</a> and follow it for updates.
<br />
Alternatively you may register at <a href="http://www.facebook.com/event.php?eid=115203467104">Facebook</a> as well and follow this for updates.



<br /><br />
For any questions please visit IRC channel: #phprp on irc.uni-erlangen.de.
<br /><br /><br />
The PHP 5.3. BBQ release party is sponsored by:
<br /><br />
<p>
<a href="http://www.microsoft.com/php" title="Microsoft "><img height="35" border="0" src="http://schlueters.de/blog/uploads/logos/mslogo-1.jpg" alt="Microsoft" /></a>  
<a href="http://www.mayflower.de" title="Mayflower GmbH"><img border="0" src="http://schlueters.de/blog/uploads/logos/mayflower.jpg" alt="Mayflower GmbH" /></a>  <br />
<a href="http://www.swoodoo.com/de" title="Swoodoo AG"><img height="100" border="0" src="http://schlueters.de/blog/uploads/logos/swoodoo_logo.jpg" alt="Swoodoo AG" /></a>  
<a href="http://www.zend.com/de" title="Zend Technologies GmbH"><img height="100" border="0" src="http://schlueters.de/blog/uploads/logos/zend_logo_color_L.gif" alt="Zend Technologies GmbH" /></a> 
</p>


<br /><br />

Supporters for the PHP 5.3 BBQ release party are:<br />
<ul>
<li><a href="http://www.sun.de" title="Sun Microsystems" style="text-decoration: none;"><strong style="font-size: 15px;">Sun Microsystems</strong></a></li>
<li><a href="http://www.phpugmunich.org" title="PHP Usergroup Munich" style="text-decoration: none;"><strong style="font-size: 15px;">PHPUG.de</strong></a></li>
</ul>
</blockquote> 
            </div>
        </content>
        <dc:subject>fun</dc:subject>
<dc:subject>party</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php53</dc:subject>
<dc:subject>releases</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/114-MySQLi-result-set-iteration-recursive.html" rel="alternate" title="MySQLi result set iteration - recursive" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-07-01T09:56:59Z</published>
        <updated>2009-07-02T16:00:27Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=114</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=114</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/114-guid.html</id>
        <title type="html">MySQLi result set iteration - recursive</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>PHP 5.3 is released and after the release stress is over my mind is open for new ideas. While relaxing yesterday I thought about many things, among them was the Resultset iterator <a href="http://schlueters.de/blog/archives/112-MySQLi-Resultset-Iterator.html">I recently discussed</a>.</p><p>Now I wondered where to go next with this and had the idea that an individual Resultset is a child of the whole result and this might be wrapped in an Recursive Iterator. For doing so we don't implement the Iterator interface but RecursiveIterator. RecursiveIterator extends a typical Iterator with two methods: hasChildren() and getChildren(). But now we have a problem: The Iterator returned by getChildren() has to be a RecursiveIterator, too, which makes sense, in general. But I want to return a MySQLi Resultset which isn't recursive - so making this a RecursiveIterator is wrong. My solution now is to introduce yet another Iterator which goes by the name of MySQLi_PseudoRecursiveResultIterator and is implemented by extending IteratorIterator which will wrap the MySQLi_Result and implements RecursiveIterator telling the caller that there are no children.</p><p>As a sidenote: In <a href="https://code.launchpad.net/php-mysqlnd">our experimental tree</a> <a href="http://hristov.com/oblog/">Andrey</a> made MySQLi_Result an iterator but that's not yet in php.net's CVS (might need some more testing, and probably we might change the design there...) so I'm emulating this with MySQLi_Result::fetch_all() combined with an ArrayIterator, using the experimental code the constructor can be dropped.</p><p>So let's finally look at the code of these two classes:</p>
<pre>&lt;?php
class MySQLi_ResultsetIterator implements RecursiveIterator
{
    private $mysqli;
    private $counter = 0;
    private $current = null;
    private $rewinded = false;

    public function __construct(mysqli $mysqli) {
        $this-&gt;mysqli = $mysqli;
    }
    private function freeCurrent() {
        if ($this-&gt;current) {
            $this-&gt;current-&gt;free();
            $this-&gt;current = null;
        }
    }
    public function rewind() {
        if ($this-&gt;rewinded) {
            throw new Exception(&quot;Already rewinded&quot;);
        }
        $this-&gt;freeCurrent();
        $this-&gt;counter = 0;
        $this-&gt;rewinded = true;
    }
    public function valid() {
        $this-&gt;current = $this-&gt;mysqli-&gt;store_result();
        return (bool)$this-&gt;current;
    }
    public function next() {
        $this-&gt;freeCurrent();
        $this-&gt;counter++;
        $this-&gt;mysqli-&gt;next_result();
    }
    public function key() {
        return $this-&gt;counter;
    }
    public function current() {
        if (!$this-&gt;current) {
            throw new Exception(&quot;valid() not called&quot;);
        }
        return $this-&gt;current;
    }

    public function hasChildren() {
        return true;
    }
    public function getChildren() {
        return new MySQLi_PseudoRecursiveResultIterator($this-&gt;current);
    }
}

class MySQLi_PseudoRecursiveResultIterator
     extends IteratorIterator
     implements RecursiveIterator
{
    public function __construct(MySQLi_Result $result) {
        // This ctor can be dropped with the experimental bzr sources
        // as IteratorIterator::__construct() directly works with
        // MySQLi_Result
        parent::__construct(new ArrayIterator($result-&gt;fetch_all()));
    }
    public function hasChildren() {
        return false;
    }
    public function getChildren() {
        throw new Exception(&quot;This should never be called&quot;);
    }    
}
?&gt;</pre>
<p>Now we can use this code. For properly using a RecursiveIterator one should use a RecursiveIteratorIterator (RII). To get some nice labels I'm extending the RII and then have a single foreach:</p>
<pre>&lt;?php
class MyRecursive_IteratorIterator
     extends RecursiveIteratorIterator
{
    public function __construct(MySQLi $mysqli, $flags = 0) {
        parent::__construct(
                new Mysqli_ResultSetIterator($mysqli),
                $flags | RecursiveIteratorIterator::LEAVES_ONLY);
    }

    public function beginChildren() {
        echo &quot;Next ResultSet:\n&quot;;
    }
}

$mysqli = new MySQLi(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;, &quot;test&quot;);

$query  = &quot;SELECT 1,2 UNION SELECT 3, 4;&quot;.
          &quot;SELECT 'hi world' UNION SELECT 'foobar'&quot;;
if ($mysqli-&gt;multi_query($query)) {
    foreach (new MyRecursive_IteratorIterator($mysqli) as $key =&gt; $row) {
        printf(&quot;    %s\n&quot;, $row[0]);
    }
}
?&gt;
</pre>
<p>Now calling this code gives us a result similar to the following:</p>
<pre>Next ResultSet:
    1
    3
Next ResultSet:
    hi world
    foobar</pre>
<p>Isn't that nice? - I think that's a cool API! What do you think? Do you have use cases for such an API? Should we implement this in C and bundle it with PHP? Any feedback welcome!</p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>iterator</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>mysqli</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>resultset</dc:subject>
<dc:subject>stored procedures</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/113-PHP-5.3-is-released.html" rel="alternate" title="PHP 5.3 is released" />
        <author>
            <name>Johannes Schlüter</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2009-06-30T11:14:23Z</published>
        <updated>2009-06-30T17:04:44Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=113</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=113</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/113-guid.html</id>
        <title type="html">PHP 5.3 is released</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>It was a long run and I'm sure it felt like an eternity for many - for me it certainly did. PHP 5.3 was branched of over two years ago and finally is ready to be <a href="http://php.net/releases/5_3_0.php">called 5.3.0</a>.</p>
<p>The php.net website and many other blogs discuss the features - from often loved closures, to well discussed namespaces to the sometimes hated goto - so I think I don't have to this here but instead can focus on that what really matters:</p>
<ul>
<li>Thanks to all the developers - Without them no new features would be there.</li>
<li>Thanks to the documentation team - Without them one would have to decipher the NEWS file and guess what exactly is meant.</li>
<li>Thanks to all participants during the Testfest! - During the Testfest we received many good tests for our regression  test suite. Many of these tests represent what people do, not what developers think they should do which is important to reduce the risk of regressions. I hope people don't stop sending tests!</li>
<li>Thanks to all the testers who reported bugs, and to the ones who reported that their applications worked without issues! - Regression tests are important but many possible issues can only be found in real life scenarios with real applications.</li>
<li>Thanks to the whole community to make pressure on the developers to finally get it out as everybody is waiting for the new features.</li>
<li>And last, but certainly not least: Thanks to Lukas! - Handling developers who are passionate for their work can be tough. Lukas made sure that the developers focus on what really matters and really helped me with all the work needed <img src="http://schlueters.de/blog/templates/schluetersde/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /> </li>
</ul>
<p>So with that: In case you didn't do already: Browse over to php.net and <a href="http://php.net/downloads.php#v5.3.0">grab your copy</a>, it's for free!</p><p>If you want to celebrate the release and are close to Munich: We're planing a <a href="http://phpugmunich.org/dokuwiki/php_release_party">PHP Release Party</a> on July 17th, details on that will follow.</p> 
            </div>
        </content>
        <dc:subject>closures</dc:subject>
<dc:subject>goto</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>namespaces</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php qa</dc:subject>
<dc:subject>php releases</dc:subject>
<dc:subject>php testfest</dc:subject>
<dc:subject>php testing</dc:subject>
<dc:subject>php53</dc:subject>
<dc:subject>phpqa</dc:subject>
<dc:subject>phpt</dc:subject>
<dc:subject>project managment</dc:subject>

    </entry>

</feed>