<?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>Pau Gay &#187; php</title>
	<atom:link href="http://paugay.com/blog/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://paugay.com/blog</link>
	<description>eres lo que haces, no lo que dices</description>
	<lastBuildDate>Mon, 14 Nov 2011 00:11:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to name interfaces / abstract classes with namespaces</title>
		<link>http://paugay.com/blog/2011/11/name-interfaces-abstract-classes-namespaces.html</link>
		<comments>http://paugay.com/blog/2011/11/name-interfaces-abstract-classes-namespaces.html#comments</comments>
		<pubDate>Mon, 14 Nov 2011 00:11:12 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[desarrollo]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://paugay.com/blog/?p=466</guid>
		<description><![CDATA[I&#8217;m building a new library with the aim to parse venues from Internet (code on Github). Well, aside from the purpose or usage of the library I&#8217;m using this project development to try to write the domain oriented code and by the way I&#8217;m facing some arquitectural problems. Basically, in the past the most common [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m building a new library with the aim to parse venues from Internet (<a href="https://github.com/paugay/venues">code on Github</a>). Well, aside from the purpose or usage of the library I&#8217;m using this project development to try to write the domain oriented code and by the way I&#8217;m facing some arquitectural problems.</p>
<p>Basically,<strong> in the past</strong> the most common convention for naming interfaces or abstract classes was the following:</p>
<p>For the interface (lib/domain/venue/interface.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> venues_domain_venue_interface <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/domain/venue/abstract.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> venues_domain_venue_abstract <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, I want to port this code to <strong>PHP 5.3 Namespace</strong> format. The translation is not that direct, note that &#8220;abstract&#8221; and &#8220;interface&#8221; are reserver keywords and I can not use then to name my clases.</p>
<p>For the interface (lib/Domain/Venue/Interface.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> <span style="color: #000000; font-weight: bold;">Interface</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/Domain/Venue/Abstract.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> Abstract <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>That will simply break with a PHP Parse Error because the &#8220;Interface&#8221; or &#8220;Abstract&#8221; are reserver keywords.</p>
<p>Researching on Internet I&#8217;ve found the following options:</p>
<p>&nbsp;</p>
<p><strong>1. Prepend the domain name</strong></p>
<p>For the interface (lib/Domain/Venue/VenueInterface.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> VenueInterface <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/Domain/Venue/VenueAbstract.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> VenueAbstract <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p><strong>2. Append the domain name</strong></p>
<p>For the interface (lib/Domain/Venue/InterfaceVenue.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> InterfaceVenue <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/Domain/Venue/AbstractVenue.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> AbstractVenue <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p><strong>3. Prepending &#8220;I&#8221; or &#8220;A&#8221;</strong></p>
<p>For the interface (lib/Domain/Venue/IVenue.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> IVenue <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/Domain/Venue/AVenue.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> AVenue <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p><strong>4. Append &#8220;Class&#8221;</strong></p>
<p>For the interface (lib/Domain/Venue/InterfaceClass.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> InterfaceClass <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>And for the abstract (lib/Domain/Venue/VenueClass.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Venues\Domain\Venue<span style="color: #339933;">;</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> VenueClass <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p><strong>References:</strong></p>
<ul>
<li><a href="http://stackoverflow.com/questions/1150098/naming-of-interfaces-abstract-classes-in-php-5-3-using-namespaces">Naming of interfaces/abstract classes in PHP 5.3 (using namespaces)</a></li>
<li><a href="http://framework.zend.com/wiki/display/ZFPROP/Naming+conventions+for+2.0+-+Matthew+Ratzloff">Zend Framework: Naming conventions for 2.0 &#8211; Matthew Ratzloff Component Proposal</a></li>
<li><a href="http://news.php.net/php.standards/2">PHP Standards and Best Practices for PHP 5.3+ Frameworks and Libraries</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2011/11/name-interfaces-abstract-classes-namespaces.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some good and bad things from PHP</title>
		<link>http://paugay.com/blog/2011/10/some-good-and-bad-things-from-php.html</link>
		<comments>http://paugay.com/blog/2011/10/some-good-and-bad-things-from-php.html#comments</comments>
		<pubDate>Fri, 28 Oct 2011 20:34:44 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/blog/?p=449</guid>
		<description><![CDATA[As a PHP developer I recognise that I&#8217;m not as opinated as I should be. When someone asks me &#8220;Why I&#8217;ve choose PHP&#8221; I just say that it&#8217;s because it was the first language I&#8217;ve deep into and I&#8217;ve keep developing myself into PHP (it&#8217;s what it allows me to develop more in less time). [...]]]></description>
			<content:encoded><![CDATA[<p>As a PHP developer I recognise that I&#8217;m not as opinated as I should be. When someone asks me &#8220;<em>Why I&#8217;ve choose PHP</em>&#8221; I just say that it&#8217;s because it was the first language I&#8217;ve deep into and I&#8217;ve keep developing myself into PHP (it&#8217;s what it allows me to develop more in less time). Once you know a language and you have enough knowledge is interesting to move into other languages so you can open your mind and get a better understanding of your preferred language (exactly like learning another spoken language). I hope I can learn any other language soon ;)</p>
<p>I&#8217;m going to summarize some pros and cons from PHP as a interesting excersise for myself:</p>
<h2>Advantages:</h2>
<ul>
<li><strong>Documentation</strong>: At the beginning is difficult to get use to (like any other documentation) but when you are into it, it&#8217;s pretty handy. My usual searches on google are &#8220;php array functions&#8221; or &#8220;php string functions&#8221;. A good point is allowing the comments from the users, some of them really interesting.</li>
<li><strong>Easy to start</strong>: It&#8217;s easy to install WAMP (on Windows) or using php on cli with *NIX. There are lots of tutorials and all-known open source projects to look at the source code to learn more (WordPress, Drupal, etc.). Furthermore, you can got a cheap host easily.</li>
<li><strong>Web optimized</strong>: Really easy to access to GET and POST variables and by default there is a direct map between the file and the URL. This kind of things make it easy to learn.</li>
<li><strong>Right model</strong>: Requests are isolated from other requests and if it goes wrong, that is too isolated, which means that you can leak memory, have terrible bugs or infinite loops and you will not kill your server beause Apache is on top of that.</li>
<li><strong>Scaling</strong>: Is relative common knowledge to scale PHP, you can search on Internet and you will find lots of tutorials, tips, etc.</li>
</ul>
<h2>Disadvantages:</h2>
<ul>
<li><strong>Error handling</strong>: There is more than a single way to handling errors: trigger_error(), Exceptions and returning codes. Not having a unique and organized way make libraries mix all of this methods and sometimes makes it difficult to trap.</li>
<li><strong>Too many falses</strong>: Not having a typed variables makes all this expressions evaluate as false: null, false, empty string, zero, the string containing &#8217;0&#8242; and empty array.</li>
<li><strong>Initialization</strong>: There is a lot of things that can be modified on the php.ini and it could change from server to server. Not a big pain but should be aware.</li>
<li><strong>Returning arrays</strong>: If a function returns an array you have to assign it to a variable before accessing an element, you can&#8217;t just add an index after the function call.</li>
<li><strong>No multiple inheritance</strong>: PHP doesn&#8217;t support multiple inheritance.</li>
<li><strong>Evolving language</strong>: The fact that it&#8217;s evolving and having new features in each release has other constraints: &#8220;register_globals&#8221; (&#8220;script.php?auth=1&#8243; sets $auth as TRUE by default), &#8220;magic_quotes&#8221; (that&#8217;s not for security and people is relying on that) and &#8220;PHP4&#8242;s object reference model&#8221; (where references didn&#8217;t point to the object, they were pointing to the variable).</li>
<li><strong>Others</strong>: Lack of case sensitivity (&#8220;$variable&#8221; is the same than &#8220;$VaRiaBLe&#8221;), needle and haystack vs haystack and needle in different array methods, having to use &#8220;array()&#8221; instead of just &#8220;[]&#8220;.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2011/10/some-good-and-bad-things-from-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error messages in Zend Form .ini file</title>
		<link>http://paugay.com/blog/2010/07/zend-form-custom-error-messages-ini.html</link>
		<comments>http://paugay.com/blog/2010/07/zend-form-custom-error-messages-ini.html#comments</comments>
		<pubDate>Sat, 24 Jul 2010 16:40:52 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[zend-framework]]></category>

		<guid isPermaLink="false">http://paugay.com/blog/?p=383</guid>
		<description><![CDATA[I was searching the way to customize the validator error messages in Zend Form using the .ini file. Finally I found two useful links: Rob Allen answering in StackOverflow One guy asking a similar question in Nabble I copy here the content of my form.ini: ; apellido elements.apellido.type = &#34;text&#34; elements.apellido.options.label = &#34;Apellido&#34; elements.apellido.options.description = [...]]]></description>
			<content:encoded><![CDATA[<p>I was searching the way to customize the validator error messages in Zend Form using the .ini file.</p>
<p>Finally I found two useful links:</p>
<ol>
<li><a href="http://stackoverflow.com/questions/1396348/zend-form-validator-custom-error-message-in-ini-configuration-file">Rob Allen answering in StackOverflow</a></li>
<li><a href="http://zend-framework-community.634137.n4.nabble.com/Zend-Form-Validators-Filters-and-ini-files-td657979.html">One guy asking a similar question in Nabble</a></li>
</ol>
<p>I copy here the content of my form.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">;</span> apellido
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>type <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;text&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Apellido&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Introduce tu apellido&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span>notempty<span style="color: #339933;">.</span>validator <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NotEmpty&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span>notempty<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>messages<span style="color: #339933;">.</span>isEmpty <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Campo requerido&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span>notempty<span style="color: #339933;">.</span>breakChainOnFailure <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #339933;">.</span>validator <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;StringLength&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #339933;">.</span>options<span style="color: #339933;">.</span><span style="color: #990000;">min</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>validators<span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #339933;">.</span>options<span style="color: #339933;">.</span><span style="color: #990000;">max</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;100&quot;</span>
elements<span style="color: #339933;">.</span>apellido<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>required <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span></pre></div></div>

<p><strong>Some useful tips that you might know:</strong></p>
<ul>
<li>If you don&#8217;t put the &#8220;options.required = true&#8221; the &#8220;NotEmpty&#8221; validator doesn&#8217;t work.</li>
<li>If you don&#8217;t put the &#8220;breakChainOnFailure = true&#8221; the form will carry on executing other validators.</li>
<li>You can search in the Zend Framework source code for the messages that you can overwrite. Look at: &#8220;Zend/Validate/*&#8221; files.</li>
</ul>
<p>I wish it will be useful for somebody =) !</p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2010/07/zend-form-custom-error-messages-ini.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Iterar sobre array en PHP y Javascript</title>
		<link>http://paugay.com/blog/2010/05/iterar-array-php-javascript.html</link>
		<comments>http://paugay.com/blog/2010/05/iterar-array-php-javascript.html#comments</comments>
		<pubDate>Wed, 26 May 2010 13:00:28 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[desarrollo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/blog/?p=368</guid>
		<description><![CDATA[¡Porfin lo encontré! En PHP hacemos el típico foreach: foreach&#40;$array as $key =&#38;gt; $value&#41; &#123; echo &#34;clave = &#34; + $key; echo &#34;valor = &#34; + $value; &#125; Y en Javascript también se puede hacer del siguiente modo: for&#40;i in array&#41; &#123; alert&#40;&#34;clave = &#34; + i&#41;; alert&#40;&#34;value = &#34; + array&#91;i&#93;&#41;; &#125;]]></description>
			<content:encoded><![CDATA[<p>¡Porfin lo encontré!</p>
<p>En <strong>PHP</strong> hacemos el típico foreach:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;clave = &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;valor = &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y en <strong>Javascript</strong> también se puede hacer del siguiente modo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> array<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;clave = &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;value = &quot;</span> <span style="color: #339933;">+</span> array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2010/05/iterar-array-php-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Función de swap sin variable aux</title>
		<link>http://paugay.com/blog/2010/05/funcion-de-swap-sin-variable-aux.html</link>
		<comments>http://paugay.com/blog/2010/05/funcion-de-swap-sin-variable-aux.html#comments</comments>
		<pubDate>Mon, 03 May 2010 06:10:28 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/blog/?p=359</guid>
		<description><![CDATA[Este es el típico problema que te ponen a veces para probar tu habilidad como programador. Tienes que hacer una función para cambiar los valores de dos variables sin usar una variable auxiliar. La función que a todos se nos ocurre és: function swap&#40;$a, $b&#41; &#123; $tmp = $a; $a = $b; $b = $tmp; [...]]]></description>
			<content:encoded><![CDATA[<p>Este es el típico problema que te ponen a veces para probar tu habilidad como programador.</p>
<blockquote><p><em>Tienes que hacer una función para cambiar los valores de dos variables sin usar una variable auxiliar.</em></p></blockquote>
<p>La función que a todos se nos ocurre és:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Pero esta no cumple el enunciado. Una posible función que si cumple el enunciado es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>Edición 05/07/2010:</em></p>
<p><strong>Juan Antonio Galán</strong>, mediante los comentarios me hace llegar esta solución:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y <strong>Víctor </strong>me comenta esta otra:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$a</span> ^<span style="color: #339933;">=</span> <span style="color: #000088;">$b</span> ^<span style="color: #339933;">=</span> <span style="color: #000088;">$a</span> ^<span style="color: #339933;">=</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Muchas gracias por vuestra aportación ;) !</p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2010/05/funcion-de-swap-sin-variable-aux.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Por qué Zend Framework?</title>
		<link>http://paugay.com/blog/2009/12/por-que-zend-framework.html</link>
		<comments>http://paugay.com/blog/2009/12/por-que-zend-framework.html#comments</comments>
		<pubDate>Sat, 26 Dec 2009 09:24:56 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[desarrollo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/?p=290</guid>
		<description><![CDATA[El otro día recibí un comentario de un lector de mi blog y me preguntaba: Pau, por que  Zend Framework? Vi que hace un tiempo habías hecho un post sobre CakePHP. Voy a dar la respuesta a este comentario en forma de post. Es cierto que había escrito un post sobre CakePHP. Un amigo (Xavier [...]]]></description>
			<content:encoded><![CDATA[<p>El otro día recibí un comentario de un lector de mi blog y me preguntaba:</p>
<blockquote><p><strong>Pau, por que  Zend Framework? Vi que hace un tiempo habías hecho un post sobre CakePHP.</strong></p></blockquote>
<p>Voy a dar la respuesta a este comentario en forma de post. Es cierto que había escrito un post sobre <a href="http://cakephp.org/">CakePHP</a>. Un amigo (<a href="http://www.alcim.net/">Xavier Orduña</a>) me lo presentó y lo probé. Entonces aún no conocí­a ningún framework de desarrollo y, al topar por primera vez con Cake, me pareció una manera muy rápida de agilizar el desarrollo de una aplicación web.</p>
<p>Un tiempo más tarde, y sin haber profundizado con Cake, probé <a href="http://framework.zend.com/">Zend Framework</a>. También me lo recomendó otro amigo (<a href="http://twitter.com/ccossio">Claudio Cossio</a>) y tengo que confesar que me gustó más que Cake.</p>
<p style="text-align: center;"><img class="aligncenter" title="zf" src="http://dev.juokaz.com/wp-content/uploads/2009/04/logo-zend-framework.jpg" alt="" width="137" height="92" /></p>
<p>Ya llevo un tiempo desarrollando con Zend y después de un par de proyectos, puedo sacar <strong>las siguientes conclusiones</strong>. Antes advierto que no soy un experto en frameworks, he tocado mas o menos en profundidad Zend, he jugado con CakePHP y Django (para Python) y me han hablado muy bien de Symphony, así que ya aviso que mi punto de vista va a estar desviado.</p>
<ol>
<li><strong>Documentación correcta:</strong> Acostumbro a consultar su documentación a menudo y está bastante bien, con ejemplos bastante bien explicados y sobretodo prácticos.</li>
<li><strong>Sencillo</strong>: Es relativamente sencillo de montar una aplicación básica con Zend Framework. Si luego quieres ir un poco más allá ya en cuanto a complejidad, ya vas a tener que mirarte la documentación.</li>
<li><strong>Completitud de módulos</strong>: Tiene módulos para casi todo. Una vez empiezas a programar con él, cada vez que revisas los módulos encuentras alguno que te va a ser útil.</li>
<li><strong>Zend está detrás</strong>: El hecho de que Zend, la compañía que desarrolla PHP está detrás de este framework me da una cierta seguridad de que será mantenido y que dará soporte por mucho tiempo.</li>
<li><strong>Patrones de base de datos:</strong> Me encanta el patrón de diseño que usa ZF para acceso a la base de datos: <em>Table Data Gateway</em> y <em>Row Data Gateway</em>. Me imagino que la mayoría de frameworks deben usar cosas parecidas, pero la manera en que lo resuelve Zend Framework es especialmente cómoda para el programador.</li>
</ol>
<p>Por último, cito las palabras del amigo <a href="http://blog.carlosbuenosvinos.com/">Carlos Buenosvinos</a> en una de las discusiones del <strong>Grupo de programadores PHP Barcelona</strong>, en respuesta a &#8220;<em>¿Qué framework PHP usáis?</em>&#8220;:</p>
<blockquote><p>Has de considerar, la comunidad, la continuidad, performance, si está basado en componentes o no (migrar o nueva aplicación desde 0), contenido en la red, libros (material didáctico), oferta de desarrolladores (en el caso de que quieras contratar), funcionalidades totales, funcionalidades que se adaptan a tus requerimientos, funcionalidades que le faltan para tu aplicación, si tienes desarrolladores en tu equipo que ya conozcan algún framework, soporte con PHP 5.3 (compatibilidad hacia atrás, sin compatibilidad, &#8230;), etc. No te dejes llevar por modas, como siempre, la respuesta es <strong>depende</strong>.</p></blockquote>
<p>Pues nada, saludos y disfruten de las vacaciones de navidad (quien las tenga!).</p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2009/12/por-que-zend-framework.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Conference 2009</title>
		<link>http://paugay.com/blog/2009/10/php-conference-2009.html</link>
		<comments>http://paugay.com/blog/2009/10/php-conference-2009.html#comments</comments>
		<pubDate>Thu, 15 Oct 2009 07:58:29 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[desarrollo]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://paugay.com/?p=280</guid>
		<description><![CDATA[La gente de PHP Barcelona se han animado, como cada año, a montar una la PHP Conference 2009, una conferéncia relacionada con PHP que se celebrará el 30 y 31 de Octubre en el Citilab, en Cornellà. Como podéis ver, el planning parece muy interesante. Seguramente asistiré, como mínimo el sábado. Para los amantes del [...]]]></description>
			<content:encoded><![CDATA[<p>La gente de <a href="http://http://phpbarcelona.org/">PHP Barcelona</a> se han animado, como cada año, a montar una la <a href="http://phpconference.es/">PHP Conference 2009</a>, una conferéncia relacionada con PHP que se celebrará el <strong>30 y 31 de Octubre</strong> en el <a href="http://citilab.eu/inici">Citilab</a>, en Cornellà. Como podéis ver, el <a href="http://phpconference.es/barcelona-php-conference-2009/schedule/">planning</a> parece muy interesante.</p>
<p style="text-align: center;"><img class="aligncenter" title="php conference 09 logo" src="http://phpbarcelona.org/files/logos/PHPBarcelona_Logo002.png" alt="" width="500" height="99" /></p>
<p>Seguramente asistiré, como mínimo el sábado. Para los amantes del Facebook han creado el evento. Si os habéis decidido a venir apuntaros e invitar a todos vuestros colegas.</p>
<blockquote><p><a rel="nofollow" href="http://www.facebook.com/event.php?eid=150863109670" target="_blank">http://www.facebook.com/event.php?eid=150863109670</a></p></blockquote>
<p>De cara a la promoción podéis seguir también a su twitter:</p>
<blockquote><p><a rel="nofollow" href="http://twitter.com/phpbarcelona" target="_blank">http://twitter.com/phpbarcelona</a></p></blockquote>
<p>Han empezado a usar el topic <strong>#phpbcn2009</strong> si alguno se anima a hablar de la conference usándolo más promoción para el evento de una manera sana y gratuita.</p>
<p>¡Espero veros ahí!</p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2009/10/php-conference-2009.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Truco mnemotécnico para CSS</title>
		<link>http://paugay.com/blog/2009/09/truco-mnemotecnico-para-css.html</link>
		<comments>http://paugay.com/blog/2009/09/truco-mnemotecnico-para-css.html#comments</comments>
		<pubDate>Fri, 25 Sep 2009 16:31:16 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/?p=272</guid>
		<description><![CDATA[Siempre que tengo que poner el margin o el padding a un div tengo dos opciones: a) La forma lenta y segura: div.ejemplo &#123; padding-top: 1px; padding-bottom: 2px; padding-left: 3px; padding-right: 4px; &#125; b) La forma corta: div.ejemplo &#123; padding: 1px 4px 2px 3px; &#125; El problema para mí es acordarme del orden de los [...]]]></description>
			<content:encoded><![CDATA[<p>Siempre que tengo que poner el <strong>margin</strong> o el <strong>padding</strong> a un <em>div</em> tengo dos opciones:</p>
<p>a) La forma lenta y segura:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.ejemplo</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>b) La forma corta:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.ejemplo</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">4px</span> <span style="color: #933;">2px</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>El problema para mí es acordarme del orden de los 4 atributos que siguen a &#8220;padding&#8221;. Lo que muchas veces hacía era añadir la siguiente línea (o simplemente me lo pegaba con un postit en la pared para tenerlo a mano):</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.ejemplo</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #808080; font-style: italic;">/* padding: up right down left */</span>
     <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">4px</span> <span style="color: #933;">2px</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Pues aquí un truquillo bien absurdo que se me ha ocurrido a mi mismo (es decir, no lo he sacado de internet):</p>
<blockquote><p>El orden de los atributos es en el mismo que las agujas del reloj (cada 15 min)</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2009/09/truco-mnemotecnico-para-css.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Funcion date() de PHP con timestamp</title>
		<link>http://paugay.com/blog/2009/09/funcion-date-de-php-con-timestamp-de-mysql.html</link>
		<comments>http://paugay.com/blog/2009/09/funcion-date-de-php-con-timestamp-de-mysql.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 17:16:48 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/?p=264</guid>
		<description><![CDATA[Si tienes en una tabla un atributo del tipo &#8220;timestamp&#8221; (es un formato de fecha, por ejemplo 2009-09-24 18:06:13) puedes updatear el valor con la siguiente instrucción: $row-&#62;last_access = date&#40;&#34;c&#34;&#41;; En vez de esta: $row-&#62;last_access = date&#40;&#34;Y-m-d H:i:s&#34;&#41;; No te va a hacer faltarecordar el dichoso formato de &#8220;Y-m-d H:i:s&#8221;. - Nota: Hoy hace un [...]]]></description>
			<content:encoded><![CDATA[<p>Si tienes en una tabla un atributo del tipo &#8220;timestamp&#8221; (es un formato de fecha, por ejemplo 2009-09-24 18:06:13) puedes updatear el valor con la siguiente instrucción:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_access</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>En vez de esta:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_access</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>No te va a hacer faltarecordar el dichoso formato de &#8220;Y-m-d H:i:s&#8221;.</p>
<p>-</p>
<p><em>Nota: Hoy hace un año justo que Miguel y yo nos fuimos de Erasmos a Reading, que tiempos!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2009/09/funcion-date-de-php-con-timestamp-de-mysql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modificar TITLE desde el código (HTML)</title>
		<link>http://paugay.com/blog/2009/05/html-modificar-titl.html</link>
		<comments>http://paugay.com/blog/2009/05/html-modificar-titl.html#comments</comments>
		<pubDate>Sat, 16 May 2009 10:57:55 +0000</pubDate>
		<dc:creator>Pau Gay</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://paugay.com/?p=238</guid>
		<description><![CDATA[Por temas de SEO necesito modificar el título de cada página dentro del código, es decir, fuera del &#60;header&#62;&#60;/header&#62;. He encontrado esta solución: &#60;?php $nombre_titulo=&#34;Este es el titulo&#34;; ?&#62; &#60;script language=&#34;javascript&#34;&#62; window.document.title = &#34;&#60;?php echo $nombre_titulo; ?&#62;&#34; &#60;/script&#62; Alguien usa otra manera más cómoda?]]></description>
			<content:encoded><![CDATA[<p>Por temas de SEO necesito modificar el título de cada página dentro del código, es decir, fuera del <strong>&lt;header&gt;&lt;/header&gt;</strong>.</p>
<p>He encontrado esta solución:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$nombre_titulo</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Este es el titulo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;script language=&quot;javascript&quot;&gt;
window.document.title = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nombre_titulo</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;
&lt;/script&gt;</pre></div></div>

<p>Alguien usa otra manera más cómoda?</p>
]]></content:encoded>
			<wfw:commentRss>http://paugay.com/blog/2009/05/html-modificar-titl.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

