<?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>Internet Strategy Guide</title>
	<atom:link href="http://phpprotip.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpprotip.com</link>
	<description>Together we can defeat the internet</description>
	<lastBuildDate>Fri, 25 Sep 2009 12:59:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Team Development [announcement]</title>
		<link>http://phpprotip.com/2009/09/php-team-development-announcement/</link>
		<comments>http://phpprotip.com/2009/09/php-team-development-announcement/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 12:59:10 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[announcement]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=168</guid>
		<description><![CDATA[Apparently my php-fu has become good enough that I've been asked to review books. So sometime in the future I will talk about Packt Publishing's book, "PHP Team Development". My complimentary copy is apparently in the mail, so hopefully I learn to read by then. 
Seriously though, I hope this book will help me tweak [...]]]></description>
			<content:encoded><![CDATA[<p>Apparently my php-fu has become good enough that I've been asked to review books. So sometime in the future I will talk about <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5wYWNrdHB1Yi5jb20v">Packt Publishing</a>'s book, "<a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5wYWNrdHB1Yi5jb20vcGhwLXRlYW0tZGV2ZWxvcG1lbnQvYm9vaw==">PHP Team Development</a>". My complimentary copy is apparently in the mail, so hopefully I learn to read by then. </p>
<p>Seriously though, I hope this book will help me tweak my current team practices. Guess I'll find out after it arrives.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=168" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/09/php-team-development-announcement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>visibility and inheritance.</title>
		<link>http://phpprotip.com/2009/08/visibility-and-inheritance/</link>
		<comments>http://phpprotip.com/2009/08/visibility-and-inheritance/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 15:16:40 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[theory crafting]]></category>
		<category><![CDATA[unittesting]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=164</guid>
		<description><![CDATA[An interesting topic came up in #phpc today. It revolved around some issues I've been encountering in my latest code designs/structures. It also leads into some side topics that I will attempt to explore.
From my point of view, the discussion centered around what is the best 'default' visibility to use for methods. Another thing touched [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting topic came up in #phpc today. It revolved around some issues I've been encountering in my latest code designs/structures. It also leads into some side topics that I will attempt to explore.</p>
<p>From my point of view, the discussion centered around what is the best 'default' visibility to use for methods. Another thing touched upon is the <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9PcGVuL2Nsb3NlZF9wcmluY2lwbGU=">Open/Closed principle</a>, which I think I subscribe to or may subscribe to(this depends on my ability to determine what half of the words in the entry mean).</p>
<p>Out of the whole discussion, here is the points I got (aka understood) out of it. Please correct me in the comments if I'm off base in any way.</p>
<p><strong>Methods should only be public when necessary. This is to help reduce the amount of side-effects that can occur because of method overrides.</strong></p>
<p>K, I can accept that and in thinking about my past code, I use to use protected more than private. I used public very sparingly.<br />
Now I find, since I started unit testing, that I have a large amount of public functions than I've had in the past. That is because I can't figure out how to test private methods. One way that I can think of is to create public methods that allow you to test the private ones. Unfortunately, this makes me wonder why the method isn't public to begin with since it seems redundant and wasteful to have these public methods to access private methods.<br />
Please note the key word methods, property accessors are a different story.<br />
The best solution (I can think of) to testing private methods is Mock Objects. Unfortunately, even though I've started to use mocks/doubles more, I'm unsure if my implementation is correct. Until I'm confident in my understanding of mocks/doubles, I worry about having false positives in test results.</p>
<p><strong>Another assertion that was made in the discussion was that private methods allow you to preserve the class' core functionality.</strong><br />
Unfortunately, no matter what the visibility of the method is, you're able to override it (and potentially mess with the core functionality you were trying to preserve).<br />
Example:</p>
<pre>
class foo{
    private function foobar() {
        echo "foo\n";
        return "foo foo\n";
    }

    public function bar() {
        echo "w00t ";
        return $this->foobar();
    }
}

class bar extends foo{
    private function foobar() {
        return "bar\n";
    }

    public function baz() {
        echo $this->bar();
    }

    public function wut() {
        echo $this->foobar();
    }
}

$f=new bar();
$f->baz();
$f->wut();
</pre>
<p>By running the above code, you get:</p>
<pre>
w00t foo
foo foo
bar
</pre>
<p>If preservation of core functionality is your main concern, then you're better off using <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzMi5waHAubmV0L21hbnVhbC9lbi9sYW5ndWFnZS5vb3A1LmZpbmFsLnBocA==">final</a>.</p>
<p>So after all that rambling, you're probably wondering what I'm trying to get to. It still comes down to visibility's effect on inheritance. The way I see it, unless you declare the method as final, you can't lock down the parent functionality because private methods can still be overridden. Trying to figure out what level of visibility for a method is a situational call. There is no correct 'default' visibility. Sure private is safer because of <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2h0dHA6Ly9lbi53aWtpcGVkaWEub3JnL3dpa2kvUHJpbmNpcGxlX29mX2xlYXN0X3ByaXZpbGVnZQ==">least privilege</a> but it makes testing a bear (or at least a bear at my current skill level in testing). Public potentially opens you up for abuse or misuse.</p>
<p>What I would still like to know is, how do you do class method visibility? How does that affect your testing methodology? Can someone give me an example (that isn't a singleton) where private is a better choice over protected? I like protected because it seems less limiting to me and my current coding style appreciates that degree of flexibility.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=164" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/08/visibility-and-inheritance/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>mysql alter table add foreign key</title>
		<link>http://phpprotip.com/2009/07/mysql-alter-table-add-foreign-key/</link>
		<comments>http://phpprotip.com/2009/07/mysql-alter-table-add-foreign-key/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 17:20:09 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[alter table add constraint]]></category>
		<category><![CDATA[alter table add foreign key]]></category>
		<category><![CDATA[errno 150]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=159</guid>
		<description><![CDATA[I recently ran into a situation where I needed to add a foreign key to a table. This seems easy at first but was actually a 3 step process compared to the couple of lines it takes in a create table sytax.
Short version: when creating your FK column, it helps to have the column definition [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a situation where I needed to add a foreign key to a table. This seems easy at first but was actually a 3 step process compared to the couple of lines it takes in a create table sytax.</p>
<p>Short version: when creating your FK column, it helps to have the column definition of the FK match the column definition. In retrospec, this seems like a no-brainer but was the heart of my problem.</p>
<p>So, you want create a FK to an existing table. Lets start by creating our table.</p>
<pre>
CREATE TABLE IF NOT EXISTS Role(
Id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
Name VARCHAR(255) NOT NULL UNIQUE,
Description TEXT DEFAULT NULL,
PRIMARY KEY(Id)
);
</pre>
<p>Pretend we pooped data into it and now it's a big pain in the ass to do a drop/create with how we want things.</p>
<p>First we add our column that will be the Foreign Key.</p>
<pre>
ALTER TABLE Role ADD COLUMN Parent int(11) UNSIGNED DEFAULT NULL;
</pre>
<p>Next we add an index. Why? <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Rldi5teXNxbC5jb20vZG9jL3JlZm1hbi81LjEvZW4vaW5ub2RiLWZvcmVpZ24ta2V5LWNvbnN0cmFpbnRzLmh0bWw=">because mysql says so</a> and FKs rely on indexes</p>
<pre>
ALTER TABLE Role ADD INDEX Parent (Parent);
</pre>
<p>Now we add our constraint.</p>
<pre>
ALTER TABLE `Role` ADD CONSTRAINT `Parent` FOREIGN KEY(`Parent`) REFERENCES `Role`(`Id`) ON DELETE SET NULL ON UPDATE SET NULL;
</pre>
<p>For fun, do</p>
<pre>
ALTER TABLE Role ADD COLUMN Parent int(11) DEFAULT NULL;
</pre>
<p>for the first step. Everything will look awesome until you get to the the last step. You'll get a wonderful "Errno 150" error and spend a bunch of time googling various key words trying to figure out what went wrong. Well, at least I did.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=159" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/07/mysql-alter-table-add-foreign-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>headers exception with Zend_Session while unit testing</title>
		<link>http://phpprotip.com/2009/06/headers-exception-with-zend_session-while-unit-testing/</link>
		<comments>http://phpprotip.com/2009/06/headers-exception-with-zend_session-while-unit-testing/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 14:57:18 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[header exception]]></category>
		<category><![CDATA[headers sent]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[zend_session]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=154</guid>
		<description><![CDATA[While the manual for Zend_Session does discuss unit testing and the read-only exception, it has no mention of an exception I encountered recently while unit testing. I admit that the reason I encountered the exception is most likely because I'm Doing It Wrong. However, given reality, I did not have time to properly make the [...]]]></description>
			<content:encoded><![CDATA[<p>While the manual for <a title=\"Zend_Session advanced usage (unit testing)\" href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwvZW4vemVuZC5zZXNzaW9uLmFkdmFuY2VkX3VzYWdlLmh0bWwjemVuZC5zZXNzaW9uLmFkdmFuY2VkX3VzYWdlLnRlc3Rpbmc=" target=\"_blank\">Zend_Session</a> does discuss unit testing and the read-only exception, it has no mention of an exception I encountered recently while unit testing. I admit that the reason I encountered the exception is most likely because I'm Doing It Wrong. However, given reality, I did not have time to properly make the class, or at least do it better. I received the following exception:</p>
<blockquote><p>exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started...'</p></blockquote>
<p>The problem was, of course, that the feedback from previous tests was already outputted to the screen. I could've solved this by playing with my test suite and just starting sessions at that level but that wouldn't have been the best solution. In fact, I'd qualify that solution under bandaids (solutions that mask a problem instead of fixing them). If you can't see why it is a bandaid, I'm happy to discuss it but for once, I"m going to try to stay on topic and not digress any further than I have.</p>
<p>So, here's the scenario:</p>
<ul>
<li>not enough time to refactor the class so that sessions are only called/created when necessary</li>
<li>sessions are being called because we're testing some auth stuff which relies on session information, we might not be able to do <a title=\"Dependency Injection\" href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9EZXBlbmRlbmN5X2luamVjdGlvbg==" target=\"_blank\">DI</a> (see above)</li>
<li>we want to minimize contributing factors to test failure so session has to be called/destroyed for the tests that need it, all other tests should never have session existing</li>
</ul>
<p>The solution? A little 'undocumented' static variable:</p>
<p><strong>Zend_Session::$_unitTestEnabled = true;</strong></p>
<p>Ok, undocumented is a bit misleading. You won't find out about it by looking at the <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwv" target=\"_blank\">Manual</a> but will find it when you're digging through the <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9hcGlkb2MvY29yZS8=" target=\"_blank\">API</a>. So it is documented, just not well. I'm guessing because it is rare to encounter the exception. I'm not surprised that I encountered it since my projects always seem to have some degree of weirdness, which makes for an interesting learning curve thats compounded with Zend's curve.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=154" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/06/headers-exception-with-zend_session-while-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magic __call() vs. multiple setters</title>
		<link>http://phpprotip.com/2009/03/magic-__call-vs-multiple-setters/</link>
		<comments>http://phpprotip.com/2009/03/magic-__call-vs-multiple-setters/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:44:46 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[debatable]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[debate]]></category>
		<category><![CDATA[i'm doing it wrong]]></category>
		<category><![CDATA[magic __call]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[php noob]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=121</guid>
		<description><![CDATA[I recently came across a situation where a few of my setProperty() methods where exactly the same. Since I've gotten into improving my coding, this bugged me because it was repetitious code.
Example:

public function setFoo($foo=null) {
	if (is_string($foo)&#124;&#124;is_numeric($foo)) {
		$this->foo=$foo;
		return $this;
	}
	throw new Custom_Example_Exception("Please provide a proper string or numeric",Custom_Example_Exception::INVALID_TYPE);
}

public function setBar($bar=null) {
	if (is_string($bar)&#124;&#124;is_numeric($bar)) {
		$this->bar=$bar;
		return $this;
	}
	throw new Custom_Example_Exception("Please provide [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a situation where a few of my setProperty() methods where exactly the same. Since I've gotten into improving my coding, this bugged me because it was repetitious code.<br />
Example:</p>
<pre>
public function setFoo($foo=null) {
	if (is_string($foo)||is_numeric($foo)) {
		$this->foo=$foo;
		return $this;
	}
	throw new Custom_Example_Exception("Please provide a proper string or numeric",Custom_Example_Exception::INVALID_TYPE);
}

public function setBar($bar=null) {
	if (is_string($bar)||is_numeric($bar)) {
		$this->bar=$bar;
		return $this;
	}
	throw new Custom_Example_Exception("Please provide a proper string or numeric",Custom_Example_Exception::INVALID_TYPE);
}
</pre>
<p>Notice a pattern there? Me too. If all my setters were like this, I could do </p>
<pre>
public function setProperty($property=null) {
	if (is_string($property)||is_numeric($property)) {
		$this->{$property}=$property;
		return $this;
	}
	throw new Custom_Example_Exception("Please provide a proper string or numeric",Custom_Example_Exception::INVALID_TYPE);
}
</pre>
<p>with appropriate traps in the __call() and maybe even __set() methods.</p>
<p>However, my situation is that not all the setters for my class follow this pattern so that solution means that I have to make __call() look for specific setters.</p>
<pre>
public function __call($method,$args) {
	$trapThese=array("Foo","Bar","Baz");
	preg_match('/set(*.?)/im',$method,$matches);
	if (!empty($matches)&&in_array($matches[1],$trapThese)) {
		if(is_string($args[0])||is_numeric($args[0])) {
		$propertyName=strtolower($matches[1]);
			$this->{$propertyName}=$args[0];
		}
		throw new Custom_Example_Exception("Please provide a proper string or numeric.\nException trapped in call to $method",Custom_Example_Exception::INVALID_TYPE);
	} else {
		$this->{$method}($args);
	}
}
</pre>
<p>And I'm pretty sure that this code snippet (<code>$this->{$method}($args);</code>) is the Wrong Way of Doing It. So I'll just have to settle for the redundant setFoo(),setBar,etc even though a part of me knows that there has to be a Better Way. Or maybe there is just No Way of Doing It Well.</p>
<p>I think it is probably only a matter of preference but in terms of testability, elegance, maintainability, whatever...what do you prefer, doing a magic __call() or making setFoo(),setBar(),setBaz,etc. </p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=121" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/03/magic-__call-vs-multiple-setters/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>zend_log_exception &#8216;bad log priority&#8217;</title>
		<link>http://phpprotip.com/2009/02/zend_log_exception-bad_log_priority/</link>
		<comments>http://phpprotip.com/2009/02/zend_log_exception-bad_log_priority/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 18:43:28 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[noobtip]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[bad log priority]]></category>
		<category><![CDATA[zend log]]></category>
		<category><![CDATA[zend_log]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=117</guid>
		<description><![CDATA[I'm writing this post because there are a few times I've gotten this particular exception and then look at the trace and can't figure out what's wrong. More often than not, I'll get to the line in the trace and be like, "wtf! there's no priority here. It's a method call not a constant". This [...]]]></description>
			<content:encoded><![CDATA[<p>I'm writing this post because there are a few times I've gotten this particular exception and then look at the trace and can't figure out what's wrong. More often than not, I'll get to the line in the trace and be like, "wtf! there's no priority here. It's a method call not a constant". This turns into, let's see if something is happening before this method is called and finally comes down to looking at the <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwvZW4vemVuZC5sb2cuaHRtbA==">Zend_Log</a> source and remember, "oh yeah, <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwvZW4vemVuZC5sb2cuaHRtbA==">Zend_Log</a> allows you to use log by priority name as a method in lieu of using the log method" and what I once thought of as slick when I read the documentation turns into a waste of a few minutes and added amount of aggrevation. So to save myself and others some time and aggrevation, I'm going to go into a bit of detail as to why you may be getting this exception.</p>
<p>Take the following for example:</p>
<pre>
// assume taht $log is a valid instance of Zend_Log
$log->addEventItem('foo','bar');
</pre>
<p>It looks like it should work, right? It won't because the correct method call would be</p>
<pre>
$log->setEventItem('foo','bar');
</pre>
<p>As I explained in the introduction, the 'bad log priority' exception will be thrown for this sort of error. This error will occur because <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwvZW4vemVuZC5sb2cuaHRtbA==">Zend_Log</a> <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L21hbnVhbC9lbi9sYW5ndWFnZS5vb3A1Lm92ZXJsb2FkaW5nLnBocA==">overloads the __call function</a> so that you can do</p>
<pre>
$log->priorityName('message');
// instead of logging with the log method
$log->log('message',Zend_Log::PRIORITY_NAME);
</pre>
<p>So if you're like me and get this exception but only see a method where this error is being thrown, you now know why and hopefully be less confused and aggrevated.</p>
<p>I wish I could provide a solution to this issue but I see no way that <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyYW1ld29yay56ZW5kLmNvbS9tYW51YWwvZW4vemVuZC5sb2cuaHRtbA==">Zend_Log</a> can contextually tell if you're wanting to use the priorityName shortcut or not. This only leaves the option of removing the the priorityName shortcut entirely, which will break somebody's code. The shortcut is nice because of its flexibility but definitely a case where <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3BocGltcGFjdC53b3JkcHJlc3MuY29tLzIwMDkvMDIvMjIvemVuZC1mcmFtZXdvcmstdGhlLWNvc3Qtb2YtZmxleGliaWxpdHktaXMtY29tcGxleGl0eS8=">flexibility can increase complexity</a> or rather, flexibility leading into complications that require complex understanding. I haven't had time to read all the arguments in the comments on the <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3BocGltcGFjdC53b3JkcHJlc3MuY29tLzIwMDkvMDIvMjIvemVuZC1mcmFtZXdvcmstdGhlLWNvc3Qtb2YtZmxleGliaWxpdHktaXMtY29tcGxleGl0eS8=">flexibility/complexity issue that Federico Cargnelutti brought up recently</a> to have an overall opinion on the matter but in regards to Zend_Log, the flexibility should've been left out. I would've preferred that Zend kept it simple and just made log the only method of logging. Or maybe I'm an edge case that logs more information than the initial event items give me.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=117" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/02/zend_log_exception-bad_log_priority/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>openid seems to hate me</title>
		<link>http://phpprotip.com/2009/02/openid-seems-to-hate-me/</link>
		<comments>http://phpprotip.com/2009/02/openid-seems-to-hate-me/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 19:40:04 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[clickjack]]></category>
		<category><![CDATA[csrf]]></category>
		<category><![CDATA[openid]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web security]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=115</guid>
		<description><![CDATA[been trying to comment on Chris Shiflett's post on the twitter "Don't Click" debacle and can't seem to get authenticated through openid. so having to post my reply here (below).
cavaet: i'm not an expert on anything and a n00b at a lot of things
liked the article, however I want to disagree that it isn't a [...]]]></description>
			<content:encoded><![CDATA[<p>been trying to comment on <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3NoaWZsZXR0Lm9yZy9ibG9nLzIwMDkvZmViL3R3aXR0ZXItZG9udC1jbGljay1leHBsb2l0">Chris Shiflett's post on the twitter "Don't Click" debacle</a> and can't seem to get authenticated through openid. so having to post my reply here (below).</p>
<p>cavaet: i'm not an expert on anything and a n00b at a lot of things</p>
<p>liked the article, however I want to disagree that it isn't a csrf attack since "The attack works by including a link or script in a page that accesses a site to which the user is known (or is supposed) to have authenticated" (according to wikipedia [oh no, i'm that guy. *sigh*]). @ramsey said it didn't affect him because he wasn't logged in on the website.</p>
<p>It seems to me that it used clickjack ui redressing to carry out the authentication exploit.</p>
<p>Want to know the funny thing? The only reason I logged into the website was to follow @shiflett.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=115" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/02/openid-seems-to-hate-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Citrix client onto Ubuntu 64-bit</title>
		<link>http://phpprotip.com/2009/01/installing-citrix-client-onto-ubuntu-64-bit/</link>
		<comments>http://phpprotip.com/2009/01/installing-citrix-client-onto-ubuntu-64-bit/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 20:04:30 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[citrix]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ubuntu 64]]></category>
		<category><![CDATA[ubuntu 64-bit]]></category>
		<category><![CDATA[ubuntu 64bit]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=109</guid>
		<description><![CDATA[Recently at work, I was told to install the citrix client. This was fine since citrix has a linux install, which did not work or spit out any error message.  After 68 tabs (not exaggerating) worth of googling, I found the reason for this was that citrix hates freedom only works on 32bit linux [...]]]></description>
			<content:encoded><![CDATA[<p>Recently at work, I was told to install the citrix client. This was fine since citrix has a linux install, which did not work or spit out any error message.  After 68 tabs (not exaggerating) worth of googling, I found the reason for this was that citrix <del datetime="2009-01-12T19:58:12+00:00">hates freedom</del> only works on 32bit linux and that there is no 64bit version out yet. YAY! after a couple thousand (exaggerating) more tabs, I was able to track down the correct way to <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cHM6Ly93aWtpLnVidW50dS5jb20vSW5zdGFsbGluZ0NpdHJpeA==">install citrix onto ubuntu 64-bit</a>.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=109" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2009/01/installing-citrix-client-onto-ubuntu-64-bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordle meme</title>
		<link>http://phpprotip.com/2008/12/wordle-meme/</link>
		<comments>http://phpprotip.com/2008/12/wordle-meme/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 14:14:01 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[meme]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wordle]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=91</guid>
		<description><![CDATA[
Joining the wordle meme late in the game because I just got ff java plugin to work.
 ]]></description>
			<content:encoded><![CDATA[<p><a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy53b3JkbGUubmV0L2dhbGxlcnkvd3JkbC8zOTg1NzYvcGhwcHJvdGlwLmNvbQ==" title=\"Wordle: phpprotip.com\"><img src="http://phpprotip.com/wp-content/uploads/2008/12/screenshot-wordle-phpprotipcom-mozilla-firefox-300x186.png" alt="" title="wordle meme" width="300" height="186" class="alignnone size-medium wp-image-90" /></a></p>
<p>Joining the wordle meme late in the game because I just got ff java plugin to work.</p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=91" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2008/12/wordle-meme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>string searching, you&#8217;re doing it wrong</title>
		<link>http://phpprotip.com/2008/12/string-searching-youre-doing-it-wrong/</link>
		<comments>http://phpprotip.com/2008/12/string-searching-youre-doing-it-wrong/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 15:01:35 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[noobtip]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[corrected]]></category>
		<category><![CDATA[fail hammer]]></category>
		<category><![CDATA[fail whale]]></category>
		<category><![CDATA[peer evaluation]]></category>
		<category><![CDATA[php noob]]></category>
		<category><![CDATA[php noobtip]]></category>
		<category><![CDATA[php strpos tutorial]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[string search]]></category>
		<category><![CDATA[strpos]]></category>
		<category><![CDATA[tutorial review]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=86</guid>
		<description><![CDATA[First off, I'm not trying to be a complete jack-ass, just a helpful one. This article, by Stefan Ashwell, popped up on my news feed and I wanted to comment on it but can't remember my login for the site and after 10 minutes of waiting the password reset email has yet to arrive. The [...]]]></description>
			<content:encoded><![CDATA[<p>First off, I'm not trying to be a complete jack-ass, just a helpful one. <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy50b3RhbC1waHAuY29tL2FydGljbGUvMTgvcGVyZm9ybWluZy1zZWFyY2hlcy1vbi1zdHJpbmdzLXVzaW5nLXN0cnBvcy8=">This article</a>, by Stefan Ashwell, popped up on my news feed and I wanted to comment on it but can't remember my login for the site and after 10 minutes of waiting the password reset email has yet to arrive. The non-arrival of the password process is irritating me and shows in this article title and my tone. </p>
<p>In <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy50b3RhbC1waHAuY29tL2FydGljbGUvMTgvcGVyZm9ybWluZy1zZWFyY2hlcy1vbi1zdHJpbmdzLXVzaW5nLXN0cnBvcy8=">the article</a>, Stefan shows how <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLnN0cnBvcy5waHA=">strpos</a> or <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLnN0cmlwb3MucGhw">stripos</a> to locate a desired string or block of text.</p>
<p>The example he gives is as follows:</p>
<pre>
if ( stripos($sentence, 'string') ) {
   // yes it does
} else {
   // no it doesn't
}
</pre>
<p>The problem with this example is that it will yield a false positive. This is a common mistake made by a lot of people. If we examine the php manual entry further we see, "Returns the <strong>numeric</strong> position of the first occurrence of needle  in the haystack  string." The key word being numeric. This means if the string position is 0, then the expression <code>( stripos($sentence, 'string') )</code> will evaluate to false.<br />
<strong><br />
EDIT: Expanded explaination on why this can yield a false positive. If the string your searching for is at the beginning of the sentence, then the position returned is <code>0</code>. When php reaches the statement <code>if ( stripos($sentence, 'string') )</code> it interprets the return value (<code>0</code>) as false.<br />
</strong></p>
<p>Here is a more expanded example:</p>
<pre>

$eval=(stripos('The quick brown fox jumped over the lazy dog','The'));

echo '($eval) : ';
echo ($eval) ? "pass\n" : "fail whale\n";
echo '($eval==0) : ';
echo ($eval==0) ? "pass\n" : "fail whale\n";
echo '($eval===false)';
echo ($eval===false) ? "pass\n" : "fail whale\n";
echo 'eval is '.$eval."\n";

/**
output is:

($eval) : fail whale
($eval==0) : pass
($eval===false)fail whale
eval is 0

*/
</pre>
<p>As you can see, if you want to properly search for a string using <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLnN0cmlwb3MucGhw">stripos</a> or <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLnN0cnBvcy5waHA=">strpos</a>, you must test for the boolean value of false ($eval===false). Alternately, you can use <a href="http://phpprotip.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3VzMi5waHAubmV0L21hbnVhbC9lbi9ib29rLnBjcmUucGhw">regex</a>, if you're comfortable with it. I'm of the opinion that learning some basic regex doesn't ever hurt you.</p>
<p>I want to re-iterate that I wanted to leave this whole post as a comment but that doesn't seem possible right now since that email has yet to arrive and the article requires login for commenting. </p>
 <img src="http://phpprotip.com/wp-content/plugins/feed-statistics.php?view=1&post_id=86" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2008/12/string-searching-youre-doing-it-wrong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
