<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bleadof's world of tinkering &#187; PHP</title>
	<atom:link href="http://hiutale.org/category/tinkering/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://hiutale.org</link>
	<description>It's just life, it'll sort itself out</description>
	<lastBuildDate>Thu, 03 May 2012 08:29:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Work and ajax</title>
		<link>http://hiutale.org/2006/07/03/work-and-ajax/</link>
		<comments>http://hiutale.org/2006/07/03/work-and-ajax/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 08:01:18 +0000</pubDate>
		<dc:creator>Bleadof</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tinkering]]></category>

		<guid isPermaLink="false">http://hiutale.org/2006/07/03/work-and-ajax/</guid>
		<description><![CDATA[Well, I was asked to do a suggesting text-box for one field in the UI so that it would be easier to type in the info which apparently is the one they make most of the errors. I did it with some script.aculo.us love. It&#8217;s nice that they have pretty good docs. So basically what [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I was asked to do a suggesting text-box for one field in the UI so that it would be easier to type in the info which apparently is the one they make most of the errors. I did it with some <a href="http://script.aculo.us/">script.aculo.us love</a>. It&#8217;s nice that they have pretty <a href="http://wiki.script.aculo.us/scriptaculous/show/Ajax.Autocompleter">good docs</a>.</p>
<p>So basically what you have to do is include</p>
<p><code><br />
&lt;head&gt;<br />
    ...<br />
    &lt;script src="scriptaculous/lib/prototype.js" type="text/javascript"&gt;&lt;/script&gt;<br />
    &lt;script src="scriptaculous/src/scriptaculous.js" type="text/javascript"&gt;&lt;/script&gt;<br />
    ...<br />
&lt;/head&gt;<br />
</code></p>
<p>Then add</p>
<p><code><br />
&lt;label for="signum"&gt;Signum&lt;/label&gt;<br />
&lt;input id="signum" name="item[signum]" type="text" /&gt;<br />
&lt;div id="signumhint" class="signumhint"&gt;&lt;/div&gt;<br />
&lt;script type="text/javascript"&gt;<br />
    // &lt;![CDATA[<br />
    new Ajax.Autocompleter("signum","signumhint","AjaxController.php?get=signum", {})<br />
    // ]]&gt;<br />
&lt;/script&gt;<br />
</code></p>
<p>Then add process the request, this is from my AjaxController.class.php draft</p>
<p><code><br />
function handleRequest($post, $get) {<br />
    if(count($post) <= 0 &#038;&#038; count($get) <= 0) {<br />
        return null;<br />
    }<br />
    if($post['item']['signum'] != null) {<br />
        $signums = $this->getSignums($post['item']['signum']);<br />
    }<br />
    $this->makeUnorderedList($signums);<br />
    $this->printList($signums);<br />
}<br />
function makeUnorderedList($results) {<br />
    $unorderedList = Array();<br />
    $unorderedList[] = '&lt;ul&gt;';<br />
    foreach($results as $result) {<br />
        $unorderedList[] = '&lt;li&gt;'.$result.'&lt;/li&gt;';<br />
    }<br />
    $unorderedList[] = '&lt;/ul&gt;';<br />
    return $unorderedList;<br />
}<br />
function printList($unorderedListArray) {<br />
    foreach($unorderedListArray as $item) {<br />
        print $item;<br />
    }<br />
}<br />
</code></p>
<p>You also need to edit your css so that the hints div will look nice. It&#8217;ll be populated data. In here the hints field css looks like this:
</p>
<p><code><br />
.signumhint {<br />
    position: absolute;<br />
    font-size: 0.8em;<br />
    background-color: white;<br />
    left: 8em;<br />
    z-index: 100;<br />
}<br />
.signumhint ul {<br />
    list-style-type:none;<br />
    margin:0px;<br />
    padding:0px;<br />
}<br />
.signumhint ul li.selected { background-color: #ffb;}<br />
.signumhint ul li {<br />
    list-style-type:none;<br />
    display:block;<br />
    margin:0;<br />
    padding:0;<br />
    height:32px;<br />
    cursor:pointer;<br />
}<br />
</code></p>
<p>And voila, you&#8217;re good to go.</p>
<p><a class="imagelink" href="http://hiutale.org/wp-content/uploads/2006/07/magazine-item-info.png" title="Ajax screenshot"><img id="image38" src="http://hiutale.org/wp-content/uploads/2006/07/magazine-item-info.thumbnail.png" alt="Ajax screenshot" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hiutale.org/2006/07/03/work-and-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP4 OOP and references</title>
		<link>http://hiutale.org/2006/06/12/php4-oop/</link>
		<comments>http://hiutale.org/2006/06/12/php4-oop/#comments</comments>
		<pubDate>Mon, 12 Jun 2006 10:32:27 +0000</pubDate>
		<dc:creator>Bleadof</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tinkering]]></category>

		<guid isPermaLink="false">http://hiutale.org/2006/06/12/php4-oop/</guid>
		<description><![CDATA[So today I decided check PHP4 OOP quirks. So now I know for sure how my code is going to behave. I wasn&#8217;t really sure how the PHP4 behaves with references so I did a test. class ReferenceTest { var $reference; function ReferenceTest() { $this->reference = new Reference(); } function getReference() { return $this->reference; } [...]]]></description>
			<content:encoded><![CDATA[<p>So today I decided check PHP4 OOP quirks. So now I know for sure how my code is going to behave. I wasn&#8217;t really sure how the PHP4 behaves with references so I did a test.</p>
<pre>
class ReferenceTest {

  var $reference;

  function ReferenceTest() {
    $this->reference = new Reference();
  }

  function getReference() {
    return $this->reference;
  }

  function &#038;getReferenceReference() {
    return $this->reference;
  }
}

class Reference {

  var $var;

  function Reference() {
    $this->var = "";
  }

  function setVar($var) {
    $this->var = $var;
  }

  function getVar() {
    return $this->var;
  }

  function &#038;getVarReference() {
    return $this->var;
  }

}

$rt =  new ReferenceTest();
$ref = $rt->getReference();
$ref->setVar("bar");
$ref2 =&#038; $rt->getReferenceReference();
$ref2->setVar("baz");
$ref3 =&#038; $rt->getReferenceReference();
$varRef =&#038; $ref3->getVarReference();
$varRef = "baf";
$ref3->setVar("foo");

print "ref:".$ref->getVar()."&lt;br/&gt;";
print "ref2:".$ref2->getVar()."&lt;br/&gt;";
print "ref3:".$ref3->getVar()."&lt;br/&gt;";
</pre>
<p>Do you know what is the output? <a href="http://hiutale.org/public/reference-test.php">Here&#8217;s the anwser.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hiutale.org/2006/06/12/php4-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP4 and error handling&#8230;</title>
		<link>http://hiutale.org/2006/04/27/php4-and-error-handling/</link>
		<comments>http://hiutale.org/2006/04/27/php4-and-error-handling/#comments</comments>
		<pubDate>Wed, 26 Apr 2006 21:30:56 +0000</pubDate>
		<dc:creator>Bleadof</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tinkering]]></category>

		<guid isPermaLink="false">http://hiutale.org/2006/04/27/php4-and-error-handling/</guid>
		<description><![CDATA[I&#8217;m working on a project at the moment. Doing stuff for company called Boogie Beat Oy. I&#8217;m doing a whole rewrite for their system-of-a-thingie&#8230; I decided to start using proper OOP-style. Pretty interesting thing to do with a language which I&#8217;ve used only for procedural programming. So I stumbled upon some of the problems which [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project at the moment. Doing stuff for company called <a href="http://www.boogiebeat.fi">Boogie Beat Oy</a>. I&#8217;m doing a whole rewrite for their system-of-a-thingie&#8230; I decided to start using proper <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OOP</a>-style. Pretty interesting thing to do with a language which I&#8217;ve used only for <a href="http://en.wikipedia.org/wiki/Procedural_programming">procedural programming</a>. So I stumbled upon some of the problems which <a href="http://en.wikipedia.org/wiki/Php#Support_for_objects">PHP4</a> has with objects and <a href="http://en.wikipedia.org/wiki/Exception_handling">error handling</a>.</p>
<h2>set_error_handler(&#8220;yourErrorHandlerFunction&#8221;)</h2>
</p>
<p>I&#8217;m used to do objects with <a href="http://en.wikipedia.org/wiki/Java_programming_language">Java</a> and<a href="http://en.wikipedia.org/wiki/Exception_handling#Exception_support_in_programming_languages">Java&#8217;s way of handling errors</a> which is quite nice and flexible.</p>
<p>In PHP4 the built in way of raising errors is:</p>
<p><code>trigger_error("Error message", E_USER_ERROR)</code></p>
<p>This is not the actual problem but the:</p>
<p><code><br />
function my_errror_handler($errno, $errstr, $errfile, $errline, $errcontext) {<br />
    switch($errno) {<br />
        case E_USER_ERROR:<br />
            ...<br />
    }<br />
}<br />
$old_error_handler = set_error_handler("my_error_handler");<br />
</code></p>
<p>Which would be just brilliant if you could say&#8230;</p>
<p><code><br />
$old_error_handler = set_error_handler("$object->errorHandler");<br />
</code></p>
<p>&#8230;and when you can&#8217;t. You&#8217;re basically bound to do like this:</p>
<p><code><br />
require('Object.class.php');<br />
$object = new Object();<br />
function __errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {<br />
    global $object;<br />
    $object->errorHandler($errno, $errstr, $errfile, $errline, $errcontext);<br />
}<br />
$oldErrorHandler = set_error_handler("__errorHandler");<br />
</code></p>
<p>Which is kind of sucky way of doing things&#8230; Basically what I&#8217;ve done is that my errorHandler will store all of the errors in an Array and I can just ask for the errors when I need to get them and it&#8217;ll return an Array of the errors. So I can easily foreach the errors in a <a href="http://smarty.php.net/">Smarty</a> template and not have to worry about the errors been print out anywhere or anytime they are triggered.</p>
<p>Took me some time to figure out a way to point to the function of this errorHandler class I wrote. This implementation is a hack but it works! It makes it easy to localize the errors if wanted because you can modify the errorHandling as you wish&#8230;</p>
<p>Here&#8217;s few documents where you can find more information about the error handling in PHP4</p>
<ul>
<li><a href="http://www.zend.com/zend/spotlight/error.php">Zend &#8211; Error handling in PHP</a></li>
<li><a href="http://fi.php.net/manual/en/function.set-error-handler.php"> php.net &#8211; Function: set_error_handler</a></li>
</ul>
<p>Oh well, that&#8217;s about it&#8230; Probably more about this later&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://hiutale.org/2006/04/27/php4-and-error-handling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

