<?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>Bubble Foundry &#187; integeters</title>
	<atom:link href="http://www.bubblefoundry.com/blog/tag/integeters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bubblefoundry.com</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 22:43:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://www.bubblefoundry.com/?pushpress=hub'/>
		<item>
		<title>Typecasting Strings to Integers in PHP</title>
		<link>http://www.bubblefoundry.com/blog/2008/08/typecasting-strings-to-integers-in-php/</link>
		<comments>http://www.bubblefoundry.com/blog/2008/08/typecasting-strings-to-integers-in-php/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 14:58:59 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[From the Laboratory]]></category>
		<category><![CDATA[integeters]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[typecasting]]></category>

		<guid isPermaLink="false">http://www.bubblefoundry.com/?p=75</guid>
		<description><![CDATA[PHP does some funny things when typecasting strings as integers and may not work the way you would expect (to be fair, it is documented). Here are some examples running under PHP 5.2.5 from the Mac OS X command line: php -r 'var_dump((int) "agbae");' int(0) php -r 'var_dump((int) "zzzzzzzzzzzzzzzzzzzzzzz");' int(0) php -r 'var_dump((int) "2agbae");' int(2) [...]]]></description>
			<content:encoded><![CDATA[<p>PHP does some funny things when typecasting strings as integers and may not work the way you would expect (to be fair, <a href="http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion">it is documented</a>). Here are some examples running under PHP 5.2.5 from the Mac OS X command line:</p>
<pre>
php -r 'var_dump((int) "agbae");'
int(0)
</pre>
<pre>
php -r 'var_dump((int) "zzzzzzzzzzzzzzzzzzzzzzz");'
int(0)
</pre>
<pre>
php -r 'var_dump((int) "2agbae");'
int(2)
</pre>
<pre>
php -r 'var_dump((float) "42165.6agbae");'
float(42165.6)
</pre>
<p>This is important to know because PHP allows you refer characters of strings just like you would the elements of an array (and somewhat similar to C&#8217;s strings):</p>
<pre>
php -r '$s = "abcdef"; var_dump($s[2]);'
string(1) "c"
</pre>
<p>However, giving an invalid key won&#8217;t given an error, depending on how your installation of PHP is configured in <code>php.ini</code>. If you give an out-of-bounds string you get an empty string:</p>
<pre>
php -r '$s = "abcdef"; var_dump($s[45]);'
PHP Notice:  Uninitialized string offset:  45 in Command line code on line 1
string(0) ""
</pre>
<p>If you give a string key, it is always for the zeroth index, since it is typecasted to an int and typecasting works as described above:</p>
<pre>
php -r '$s = "abcdef"; var_dump($s['zzzzz']);'
PHP Notice:  Use of undefined constant zzzzz - assumed 'zzzzz' in Command line code on line 1
string(1) "a"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bubblefoundry.com/blog/2008/08/typecasting-strings-to-integers-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
