<?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>Hyperthèse &#187; Trucs et astuces</title>
	<atom:link href="http://hyperthese.net/category/programmation/php/trucs-et-astuces/feed/" rel="self" type="application/rss+xml" />
	<link>http://hyperthese.net</link>
	<description>La connaissance supposée fausse</description>
	<lastBuildDate>Mon, 14 Jun 2010 17:32:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Statut de connexion dans PHP</title>
		<link>http://hyperthese.net/statut-de-connexion-dans-php/</link>
		<comments>http://hyperthese.net/statut-de-connexion-dans-php/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 16:59:04 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Trucs et astuces]]></category>

		<guid isPermaLink="false">http://hyperthese.net/?p=254</guid>
		<description><![CDATA[Ces derniers je fais un peu de push en HTTP, donc une information importante pour moi est le statut de connexion. En théorie cette information m&#8217;est donnée par la fonction connection_status(). Mais il faut savoir comment PHP connait ce statut (je n&#8217;ai regardé que pour le mod_php5 de apache et le cgi, mais c&#8217;est probablement [...]]]></description>
			<content:encoded><![CDATA[<p>Ces derniers je fais un peu de push en HTTP, donc une information importante pour moi est le statut de connexion. En théorie cette information m&#8217;est donnée par la fonction <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLnBocC5uZXQvY29ubmVjdGlvbl9zdGF0dXM=">connection_status()</a>. Mais il faut savoir comment PHP connait ce statut (je n&#8217;ai regardé que pour le mod_php5 de apache et le cgi, mais c&#8217;est probablement vrai dans les autres cas) : en fait, le serveur web n&#8217;envoit jamais de signal à PHP pour dire &#8220;hop c&#8217;est bon on n&#8217;a plus besoin de toi ta gueule&#8221; quand l&#8217;utilisateur ferme sa connexion. PHP ne se rend compte de la fermeture de la connexion uniquement quand il tente d&#8217;envoyer des données au serveur, car le serveur lui dit &#8220;non je peux pas écrire les données, la connexion est fermée&#8221;.</p>
<p>En d&#8217;autres termes, si vous attendez un évènement (grâce à une fonction bloquante par exemple), même si vous appellez régulièrement la fonction <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLnBocC5uZXQvY29ubmVjdGlvbl9zdGF0dXM=">connection_status()</a> le résultat sera faux car vous n&#8217;avez envoyé aucune donnée. Et encore plus grave, si vous attendez votre évènement avec une fonction bloquante, le processus passe en mode S (sleep), ce qui fait que le temps est <em>stoppé</em>, et que le <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L21hbnVhbC9lbi9pbmZvLmNvbmZpZ3VyYXRpb24ucGhwI2luaS5tYXgtZXhlY3V0aW9uLXRpbWU=">max_execution_time</a> n&#8217;est jamais atteint : le processus reste bloqué là éternellmement. Face à ça, pas beaucoup de solutions&#8230; Vous pouvez envoyer un espace chaque seconde (en n&#8217;obliant pas d&#8217;appeller <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLm9iLWZsdXNoLnBocA==">ob_flush()</a> et <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLnBocC5uZXQvbWFudWFsL2VuL2Z1bmN0aW9uLmZsdXNoLnBocA==">flush()</a>), ou alors vous pouvez faire des timeouts et faire en sorte que le client refasse une requête juste après, ou autre hack du genre&#8230; Vous pouvez aussi vous passer de PHP, mais ça c&#8217;est une autre histoire <img src='http://hyperthese.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&#038;post_id=254" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/statut-de-connexion-dans-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chaîne aléatoire en PHP</title>
		<link>http://hyperthese.net/chaine-aleatoire-en-php/</link>
		<comments>http://hyperthese.net/chaine-aleatoire-en-php/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 23:08:55 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[Trucs et astuces]]></category>

		<guid isPermaLink="false">http://hyperthese.net/?p=232</guid>
		<description><![CDATA[Ça sert toujours, une fonction pour générer une chaîne aléatoire :
PLAIN TEXT
PHP:




function randStr&#40;$len, $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"&#41; &#123;


&#160; &#160; $as = strlen&#40;$alphabet&#41; - 1;


&#160; &#160; $str = "";


&#160;


&#160; &#160; for&#40;$i = 0; $i &#60;$len; $i++&#41; &#123;


&#160; &#160; &#160; &#160; $str .= $alphabet&#91;rand&#40;0, $as&#41;&#93;;


&#160; &#160; &#125;


&#160;


&#160; &#160; return $str;


&#125; 






 ]]></description>
			<content:encoded><![CDATA[<p>Ça sert toujours, une fonction pour générer une chaîne aléatoire :</p>
<div class="igBar"><span id="lphp-2"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-2'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> randStr<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$len</span>, <span style="color:#0000FF;">$alphabet</span> = <span style="color:#FF0000;">"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$as</span> = <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3N0cmxlbg=="><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$alphabet</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$str</span> = <span style="color:#FF0000;">""</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">for</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$i</span> = <span style="color:#CC66CC;color:#800000;">0</span>; <span style="color:#0000FF;">$i</span> &lt;<span style="color:#0000FF;">$len</span>; <span style="color:#0000FF;">$i</span>++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$str</span> .= <span style="color:#0000FF;">$alphabet</span><span style="color:#006600; font-weight:bold;">&#91;</span><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3JhbmQ="><span style="color:#000066;">rand</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">0</span>, <span style="color:#0000FF;">$as</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$str</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&post_id=232" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/chaine-aleatoire-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP : les meilleures erreurs</title>
		<link>http://hyperthese.net/php-les-meilleures-erreurs/</link>
		<comments>http://hyperthese.net/php-les-meilleures-erreurs/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 01:58:10 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Trucs et astuces]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://hyperthese.net/php-les-meilleures-erreurs/</guid>
		<description><![CDATA[Il faut avouer, PHP peut faire de magnifiques erreurs. Voici deux petits exemples :
PLAIN TEXT
PHP:




&#60;?php


function bug&#40;string $str&#41; &#123;&#125;


bug&#40;"bonjour"&#41;;


?&#62; 






Ceci donne une magnifique erreur :
Catchable fatal error: Argument 1 passed to bug() must be an instance of string, string given
Une autre erreur, qui celle ci ne s'invente pas :
PLAIN TEXT
PHP:




&#60;?php :: ?&#62; 






Avec comme résultat :
Parse [...]]]></description>
			<content:encoded><![CDATA[<p>Il faut avouer, PHP peut faire de magnifiques erreurs. Voici deux petits exemples :</p>
<div class="igBar"><span id="lphp-5"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-5'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> bug<span style="color:#006600; font-weight:bold;">&#40;</span>string <span style="color:#0000FF;">$str</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">bug<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"bonjour"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ceci donne une magnifique erreur :</p>
<pre>Catchable fatal error: Argument 1 passed to bug() must be an instance of string, string given</pre>
<p>Une autre erreur, qui celle ci ne s'invente pas :</p>
<div class="igBar"><span id="lphp-6"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-6'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> :: <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Avec comme résultat :</p>
<pre>Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM</pre>
<p>Et là vous vous dites, mais qu'est-ce qu'un PAAMAYIM_NEKUDOTAYIM ? Haha, la réponse est sur <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLndpa2lwZWRpYS5vcmcvd2lraS9QYWFtYXlpbV9OZWt1ZG90YXlpbQ==">wikipedia</a> : il s'agit du nom donné à l'opérateur de résolution de scope ("::") en PHP...</p>
<p>Vive PHP !</p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&post_id=130" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/php-les-meilleures-erreurs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimisation PHP</title>
		<link>http://hyperthese.net/optimisation-php/</link>
		<comments>http://hyperthese.net/optimisation-php/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 00:55:26 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Trucs et astuces]]></category>

		<guid isPermaLink="false">http://hyperthese.net/optimisation-php/</guid>
		<description><![CDATA[Voici un slide d'excellent conseil sur l'optimisation en PHP. Il regorge de tout un tas de tests que j'ai toujours voulu faire et que j'ai toujours eu la flemme de faire...
http://ilia.ws/files/phptek2007_performance.pdf
 ]]></description>
			<content:encoded><![CDATA[<p>Voici un slide d'excellent conseil sur l'optimisation en PHP. Il regorge de tout un tas de tests que j'ai toujours voulu faire et que j'ai toujours eu la flemme de faire...</p>
<p><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2lsaWEud3MvZmlsZXMvcGhwdGVrMjAwN19wZXJmb3JtYW5jZS5wZGY=">http://ilia.ws/files/phptek2007_performance.pdf</a></p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&post_id=80" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/optimisation-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easter Eggs</title>
		<link>http://hyperthese.net/easter-eggs/</link>
		<comments>http://hyperthese.net/easter-eggs/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 17:09:46 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Humour]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Trucs et astuces]]></category>

		<guid isPermaLink="false">http://hyperthese.net/easter-eggs/</guid>
		<description><![CDATA[Les Easter Eggs (oeufs de pâques) ne se trouvent pas que le matin de Pâques dans le jardin : si on cherche bien, on peut en trouver dans certains applications telles que Firefox, Open Office ou Aptitude. Il s'agit la plupart du temps d'une blague, ou d'un mini jeu, comme dans Open Office. Voici donc [...]]]></description>
			<content:encoded><![CDATA[<p>Les Easter Eggs (oeufs de pâques) ne se trouvent pas que le matin de Pâques dans le jardin : si on cherche bien, on peut en trouver dans certains applications telles que Firefox, Open Office ou Aptitude. Il s'agit la plupart du temps d'une blague, ou d'un mini jeu, comme dans Open Office. Voici donc une liste non exhaustive de ce que vous pourrez trouver :</p>
<h3>Mozilla/Firefox</h3>
<p>Au fil des versions de Mozilla et/ou Firefox, les développeurs ont pris soin d'écrire une "Bible" de Mozilla, dont un nouveau verset est ajouté à chaque version majeure. Pour lire le verset de votre version, tapez <em>about:mozilla</em> dans la barre d'addresse, et validez.</p>
<div style="text-align: center;"><img id="image68" src="http://hyperthese.net/wp-content/uploads/2007/09/bookofmozilla.png" alt="about:mozilla" /></div>
<h3>Apt-get et Aptitude</h3>
<p>Les deux gestionnaires de paquet font décidément tout pareil...  Même dans les easter eggs <img src='http://hyperthese.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Il existe une opération non documentée et pourtant implémentée dans chacun des deux. Pour vous en convaincre, tapez dans un terminal :</p>
<pre>apt-get moo</pre>
<p>La même opération est possible sous aptitude, mais comme aptitude fait toujours mieux les choses, leur moo se déroule en plusieurs étapes. Pour l'étape 1 :</p>
<pre>aptitude moo</pre>
<p>L'étape 2 :</p>
<pre>aptitude -v moo</pre>
<p>L'étape 3 :</p>
<pre>aptitude -vv moo</pre>
<p>Et ainsi desuite jusqu'à ce que le message arrête de changer.</p>
<p>Note: testez le moo d'apt-get sous différentes distributions, il n'est pas le même partout !</p>
<h3>PHP</h3>
<p>Et oui, PHP posède aussi son (ou plutôt ses) Easter Eggs. Pour cela il suffit d'ajouter une variable dans l'URL de n'importe quel site fait en PHP. La variable en question c'est <em>?=PHPE9568F36-D428-11d2-A769-00AA001ACF42</em> ou <em>?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000</em> (les deux affichent quelquechose de différent). Par exemple, on passe de <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2h5cGVydGhlc2UubmV0Lw==">http://hyperthese.net/</a> à <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2h5cGVydGhlc2UubmV0Lz89UEhQQjhCNUYyQTAtM0M5Mi0xMWQzLUEzQTktNEM3QjA4QzEwMDAw">http://hyperthese.net/?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000</a></p>
<h3>OpenOffice.org</h3>
<p>Pour finir ce petit listing des Easter Eggs, voici celui d'OOo qui je crois mérite la palme du plus gros. Dans un premier temps, ouvrez un classeur. Dans une cellule, tapez <em>=game()</em></p>
<div style="text-align: center;"><img id="image70" src="http://hyperthese.net/wp-content/uploads/2007/09/step1.png" alt="OOo EE - Step 1" /></div>
<p>Une fois validé, vous obtenez un joli message dans la cellule :</p>
<div style="text-align: center;"><img id="image71" src="http://hyperthese.net/wp-content/uploads/2007/09/step2.png" alt="OOo EE - Step 2" /></div>
<p>Là il ne vous reste plus qu'à rééditer la cellule, puis à appuyer sur "entrée"</p>
<div style="text-align: center;"><img id="image72" src="http://hyperthese.net/wp-content/uploads/2007/09/step3.png" alt="OOo EE - Step 3" /></div>
<p>Il parraitrait que ce n'est pas le seul je, visiblement vous pouvez aussi tester "Froggle" et "TicTacToe" mais personellement je n'ai jamais eu aucun résultat....</p>
<p></p>
<h3>The End</h3>
<p>Et voici donc la fin de cette petite liste... N'hésitez pas à faire tourner google, car il y a fort à parier que votre logiciel favoris posède son easter egg ! <img src='http://hyperthese.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&post_id=69" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/easter-eggs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Valeur d&#8217;une exprssion en PHP</title>
		<link>http://hyperthese.net/valeur-dune-exprssion-en-php/</link>
		<comments>http://hyperthese.net/valeur-dune-exprssion-en-php/#comments</comments>
		<pubDate>Sat, 03 Mar 2007 15:57:46 +0000</pubDate>
		<dc:creator>Rémy Sanchez</dc:creator>
				<category><![CDATA[Trucs et astuces]]></category>

		<guid isPermaLink="false">http://remy.is-a-geek.org/valeur-dune-exprssion-en-php/</guid>
		<description><![CDATA[Leçon du jour : les expressions et leurs valeurs en PHP. Commençons par les conditions:
PLAIN TEXT
PHP:




&#60;?php


// Roulette russe


if &#40;rand&#40;1,6&#41; == 3&#41; &#123;


&#160; &#160; print &#40;"Tu est mort !"&#41;;


&#125;


?&#62; 






Le principe est simple, dans un if (&#60;expression&#62;), l'expression est évaluée et si il s'avère être équivalente à true alors la condition est validée. En PHP, tout [...]]]></description>
			<content:encoded><![CDATA[<p>Leçon du jour : les expressions et leurs valeurs en PHP. Commençons par les conditions:</p>
<div class="igBar"><span id="lphp-15"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-15'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-15">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Roulette russe</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3JhbmQ="><span style="color:#000066;">rand</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1</span>,<span style="color:#CC66CC;color:#800000;">6</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3ByaW50"><span style="color:#000066;">print</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Tu est mort !"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Le principe est simple, dans un <i>if (&lt;expression&gt;)</i>, l'expression est évaluée et si il s'avère être équivalente à <i><i>true</i></i> alors la condition est validée. En PHP, tout (à l'exception des opérateurs) a pour but de retourner une valeur : une fonction retournera une valeur, ou une variable retournera une valeur (sans parler des valeurs elles mêmes...). Donc la première chose que fait PHP (ce n'est pas tout à fait exact, mais on reviendra sur ce point plus tard) dans l'évaluation de ces expressions, c'est de chercher les valeurs. Dans l'exemple précédent, on admettra que <i>rand(1,6)</i> retourne la valeur 3. Le <i>if</i> de l'exemple ressemble donc maintenant pour le moteur PHP à</p>
<div class="igBar"><span id="lphp-16"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-16'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">3</span> == <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Maintenant intervienne les opérateurs : l'opérateur <i>==</i> demande la comparaison des valeurs qui lui sont à sa droite et à sa gauche pour savoir si elles sont équivalentes (c'est à dire que si les deux valeurs ne sont pas du même type elles sont converties dans le même type puis comparées), et si c'est effectivement le cas il retournera le <i><i>true</i></i> que le <i>if</i> attend pour considérer que la condition soit vraie.</p>
<p>Mais les opérateurs de comparaison ne sont pas les seuls opérateurs existants. À commencer par les parenthèses : si une expression se trouve entre parenthèses, alors elle est d'abord évaluée puis sa valeur est retournée. Par exemple on peut avoir (on suppose toujours que <i>rand(1,6)</i> retourne la valeur 3):</p>
<div class="igBar"><span id="lphp-17"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-17'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-17">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Roulette russe</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$num</span> = <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3JhbmQ="><span style="color:#000066;">rand</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1</span>,<span style="color:#CC66CC;color:#800000;">6</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">1</span>+<span style="color:#CC66CC;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3ByaW50"><span style="color:#000066;">print</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Tu est mort !"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3ByaW50"><span style="color:#000066;">print</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"T'as du bol d'être tombé sur le numéro "</span> . <span style="color:#0000FF;">$num</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ici encore on se retrouvera avec un</p>
<div class="igBar"><span id="lphp-18"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-18'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC66CC;color:#800000;">3</span> == <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Viennent ensuite les opérateurs logiques, et ce sont eux qui me font mentir sur la première partie : les opérateurs logiques (and, or, xor, not, ils sont détaillés <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2ZyLnBocC5uZXQvbWFudWFsL2ZyL2xhbmd1YWdlLm9wZXJhdG9ycy5sb2dpY2FsLnBocA==">dans le manuel</a>) interviennent dans l'ordre des opérations. En effet, si deux expressions sont de part et d'autre d'un <i>or</i>, par définition il suffit que l'une seule d'entre elles soit vérifiée pour que la condition soit vraie. Donc si la première expression retourne une valeur équivalente à <i><i>true</i></i>, PHP n'a pas besoin d'évaluer la seconde puique la condition est validée. En revance pour <i>and</i> et <i>xor</i> les deux expressions sont évaluées puisque PHP a besoin de connaître les deux valeurs.</p>
<p>Vous devez maintenant penser que ces système de valeurs ne marchent que dans des conditions ou autre structures de contrôle (<i>elseif</i>, <i>while</i>, <i>for</i>, etc). Eh bien pas du tout : ça marche n'importe où dans le code. De cette manière on peut avoir quelquechose qui ressemble à </p>
<div class="igBar"><span id="lphp-19"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-19'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$a</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$b</span> = <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Affiche 3</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L2VjaG8="><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$a</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>(il faut avouer que ceci ne sert à rien), on peut aussi faire (plus utile cette fois)</p>
<div class="igBar"><span id="lphp-20"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-20'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * Ici on regarde les valeurs d'un formulaire qui peut être</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * envoyé soit par POST soit par GET</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> */</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$actif</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"actif"</span><span style="color:#006600; font-weight:bold;">&#93;</span> or <span style="color:#0000FF;">$_GET</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"actif"</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>ou encore (là c'est réélement utile)</p>
<div class="igBar"><span id="lphp-21"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-21'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-21">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * Dans cet exemple, la fonction maFonction() est une fonction quelconque</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * qui retourne &lt;i&gt;true&lt;/i&gt; ou &lt;i&gt;false&lt;/i&gt; selon qu'elle réussisse ou non.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Par la méthode classique</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!maFonction<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3RyaWdnZXJfZXJyb3I="><span style="color:#000066;">trigger_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Erreur lors de l'éxecution de ma fonction !"</span>, <span style="color:#000000; font-weight:bold;">E_USER_WARNING</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Et en utilisant or</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">maFonction<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> or <a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L3RyaWdnZXJfZXJyb3I="><span style="color:#000066;">trigger_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Erreur lors de l'éxecution de ma fonction !"</span>, <span style="color:#000000; font-weight:bold;">E_USER_WARNING</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Petite explication sur ce dernier : PHP évalue d'abord <i>maFonction()</i>, qui retourne soit <i>true</i> soit <i>false</i>. Si <i>maFonction()</i> retourne <i>true</i> alors PHP n'a pas besoin d'évaluer ce qui se trouve après le or, en revanche si <i>maFonction()</i> retoure <i>false</i> PHP doit évaluer la 2<sup>ème</sup> expression.</p>
<p>Et tant qu'on est sur les valeurs, on pourra signaler que l'on peut forcer le type d'une valeur lors d'un assignement en spécifiant simplement le type entre parenthèses juste après l'opérateur d'assignation. Par exemple :</p>
<div class="igBar"><span id="lphp-22"><a href="http://hyperthese.net/wp-content/plugins/feed-statistics.php?url=Iw==" onclick=\"javascript:showCodeTxt('php-22'); return false;\">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-22">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/* On récupère l'âge depuis un formulaire, mais il est</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> * de type string, or on le veut de type int.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;"> */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$age</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>int<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"age"</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Je concluerai sur une dernière précision à propos de la sécurité : faites très attention à utiliser l'opérateur d'égalité (===) le plus possible au profit de l'opérateur d'équivalence (==) qui entraîne la conversion des types, ce qui peut mener à des abérations de logique ou des failles de sécurité (par exemple une faille de phpBB utilisait la conversion implicite des types pour devenir administrateur en modifiant simplement son identifiant de session...)</p>
<p>Voici donc un petit tour des valeurs en PHP, en espérant avoir été assez clair...</p>
 <img src="http://hyperthese.net/wp-content/plugins/feed-statistics.php?view=1&post_id=28" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://hyperthese.net/valeur-dune-exprssion-en-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
