<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Codeur Malin</title>
    <description>The latest articles on Forem by Codeur Malin (@codeurm).</description>
    <link>https://forem.com/codeurm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F364704%2Fb61923cd-4c0c-4514-9d9b-8d60106a1957.jpg</url>
      <title>Forem: Codeur Malin</title>
      <link>https://forem.com/codeurm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codeurm"/>
    <language>en</language>
    <item>
      <title>Today I found a bug !</title>
      <dc:creator>Codeur Malin</dc:creator>
      <pubDate>Fri, 24 Apr 2020 16:58:30 +0000</pubDate>
      <link>https://forem.com/codeurm/today-i-found-a-bug-2obc</link>
      <guid>https://forem.com/codeurm/today-i-found-a-bug-2obc</guid>
      <description>&lt;p&gt;Hello, &lt;/p&gt;

&lt;p&gt;I like coding, I do that everyday but something strange happened to me today. I work in a company that use extern library with API for his business and I have for mission to update a block that use one of this services with extra data.&lt;/p&gt;

&lt;p&gt;Humm.. ok no problem. I'm used to doing this kind of things. &lt;br&gt;
I start to read in the documentation of this library to find out me how it works, and.. Ok I show it.&lt;/p&gt;

&lt;p&gt;I'm ready to code, I go in my terminal create a new branch from preprod and let's go. &lt;br&gt;
Time flies, I see things take shape I'm glad but when I test I don't get what I expected. Oooookay I should miss something, I go to the documentation recheck if I forget something but no all look good. &lt;/p&gt;

&lt;p&gt;OK maybe there are a dependencies problem ? I check my composer.. Yeah maybe if I update this one it will works. Let's go for that !&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o6wNSTMj6KHBEIguY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o6wNSTMj6KHBEIguY/giphy.gif" alt="A few minutes later"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still same errors grrr !&lt;/p&gt;

&lt;p&gt;OK why you don't work *** !?&lt;br&gt;
I don't have a great debugger to help me to find a solution but I saw all Rambo movies and I know what has to be done. I decide to put on a bandanna on my head and dump my request every place where he go to find where it goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3oz8xI5c0K0hFPwmGI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oz8xI5c0K0hFPwmGI/giphy.gif" alt="Go Rambo go !"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started by putting dump in 2 places, first at the end of my code to show if I send correct data (just to be sure because in theorie I have already test that)&lt;br&gt;
And the other place is directly in the library i use for make connection with this service, juste before the request is sent correctly.&lt;/p&gt;

&lt;p&gt;So the first dump I have put, looks ok the data look like it's demand. &lt;br&gt;
And the second, looks good too.. Damnit ! &lt;/p&gt;

&lt;p&gt;OK I'm confused, I don't know why it doesn't work but there are a fact it's doesn't works. Code isn't magic there are necessarily somewhere a thing who's going bad. &lt;br&gt;
Well, let's try something else. Humm.. I will simulate the call with Postman maybe I will show a new errors message that can help me ?&lt;br&gt;
So I do that and.. It works !&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/37QADdG7V5bo9ToyCX/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/37QADdG7V5bo9ToyCX/giphy.gif" alt="Magic !"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait.. what ?!&lt;br&gt;
It works, but I do the same things.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To tell the truth at this moment I am nevertheless delighted to have a good result&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Why in Postman it works but not when I execute my code ? I'm sure now my data are good so I check carefully every data send in the library are correct and.. &lt;strong&gt;voila&lt;/strong&gt; I found It !!&lt;/p&gt;

&lt;p&gt;I did not pay attention but the library convert boolean to integer and there goes the shit. It sounds futile but the typehint is very important.&lt;/p&gt;

&lt;p&gt;So after discovery that bug, I went to the Github repository of that library and make a &lt;a href="https://github.com/HubSpot/hubspot-php/pull/313"&gt;pull request&lt;/a&gt; with a little fix. Pending, I make a fork of this repository with the fix and use it directly in my project.&lt;/p&gt;

&lt;p&gt;Today I found a bug and I tried to fix it !&lt;/p&gt;

&lt;p&gt;And you have you already found a bug in a library ?&lt;/p&gt;

&lt;p&gt;Thank for reading, &lt;br&gt;
Codeur M&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>story</category>
      <category>opensource</category>
      <category>github</category>
    </item>
    <item>
      <title>PHP Tips : How to use optimized built-it functions  ?</title>
      <dc:creator>Codeur Malin</dc:creator>
      <pubDate>Wed, 15 Apr 2020 15:43:26 +0000</pubDate>
      <link>https://forem.com/codeurm/php-tips-how-to-use-optimized-built-it-functions-32be</link>
      <guid>https://forem.com/codeurm/php-tips-how-to-use-optimized-built-it-functions-32be</guid>
      <description>&lt;p&gt;Did you already use built-in function in PHP like &lt;code&gt;count&lt;/code&gt;, &lt;code&gt;strlen&lt;/code&gt; or &lt;code&gt;in_array&lt;/code&gt; ? &lt;br&gt;
I think so, these are essential but do you know there are some of these functions that can be executed faster !? Thanks to OpCode optimized.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;OpCode you said ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yeah OpCode, you know this is the list of instructions that are generated when your php code is compiled and easier interpreted by the computer.&lt;/p&gt;

&lt;p&gt;For exemple this code :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'This is my string !'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will generate this OpCode :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;line     #* E I O op                         fetch       ext  return  operands
--------------------------------------------------------------------------------
   5     0  E &amp;gt;   ASSIGN                                              !0, 'This+is+my+string+%21'
   6     1        INIT_NS_FCALL_BY_NAME                               'foo%5Cstrlen'
         2        SEND_VAR_EX                                         !0
         3        DO_FCALL                                 0          
         4      &amp;gt; RETURN                                              1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And some functions like &lt;code&gt;strlen&lt;/code&gt; has is own opCode (you can see this in the next pictures at line 6)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;line     #* E I O op            fetch          ext  return  operands
---------------------------------------------------------------------------
   5     0  E &amp;gt;   ASSIGN                                    !0, 'This+is+my+string+%21'
   6     1        STRLEN                            ~2      !0        
         2        FREE                                      ~2
         3      &amp;gt; RETURN                                    1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of use a call to a function &lt;code&gt;INIT_NS_FCALL_BY_NAME&lt;/code&gt; you can use the OpCode &lt;code&gt;STRLEN&lt;/code&gt; directly that was optimized.&lt;/p&gt;

&lt;p&gt;This OpCode is not use by default when you are in a namespace (like my exemple), if you want to use the optimized version you have to prefix your built-it function by a backslash &lt;code&gt;\&lt;/code&gt; like this : &lt;code&gt;\strlen('foo bar')&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To compare the performance of the two versions, I make a little script which use strlen in a loop with and without backslash and this is the result :&lt;/p&gt;

&lt;h2&gt;
  
  
  Not optimized strlen in a loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'this is my string !'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsvryn0rkeimf88cf6vh1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsvryn0rkeimf88cf6vh1.png" alt="strlen not optimized"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimized \strlen always in a loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;\strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'this is my string !'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz2f0cws8dg0o86oi23bj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz2f0cws8dg0o86oi23bj.png" alt="strlen optimized"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's a micro optimization, but always good to take.&lt;br&gt;
A list of opCode was introduced with PHP 7.0, you can see it bellow:&lt;/p&gt;
&lt;h4&gt;
  
  
  Most useful functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/function.count.php" rel="noopener noreferrer"&gt;count&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/function.strlen" rel="noopener noreferrer"&gt;strlen&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/function.in-array" rel="noopener noreferrer"&gt;in_array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/function.array-key-exists" rel="noopener noreferrer"&gt;array_key_exists&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Comparison functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;is_null&lt;/li&gt;
&lt;li&gt;is_bool&lt;/li&gt;
&lt;li&gt;is_long&lt;/li&gt;
&lt;li&gt;is_int&lt;/li&gt;
&lt;li&gt;is_integer&lt;/li&gt;
&lt;li&gt;is_float&lt;/li&gt;
&lt;li&gt;is_double&lt;/li&gt;
&lt;li&gt;is_real&lt;/li&gt;
&lt;li&gt;is_string&lt;/li&gt;
&lt;li&gt;is_array&lt;/li&gt;
&lt;li&gt;is_object&lt;/li&gt;
&lt;li&gt;is_resource&lt;/li&gt;
&lt;li&gt;is_callable&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Cast functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;boolval&lt;/li&gt;
&lt;li&gt;intval&lt;/li&gt;
&lt;li&gt;floatval&lt;/li&gt;
&lt;li&gt;doubleval&lt;/li&gt;
&lt;li&gt;strval&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Other functions
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;chr&lt;/li&gt;
&lt;li&gt;ord&lt;/li&gt;
&lt;li&gt;dirname&lt;/li&gt;
&lt;li&gt;defined&lt;/li&gt;
&lt;li&gt;constant&lt;/li&gt;
&lt;li&gt;define&lt;/li&gt;
&lt;li&gt;gettype&lt;/li&gt;
&lt;li&gt;get_class&lt;/li&gt;
&lt;li&gt;get_called_class&lt;/li&gt;
&lt;li&gt;func_num_args&lt;/li&gt;
&lt;li&gt;func_get_args&lt;/li&gt;
&lt;li&gt;function_exists&lt;/li&gt;
&lt;li&gt;extension_loaded&lt;/li&gt;
&lt;li&gt;call_user_func_array&lt;/li&gt;
&lt;li&gt;call_user_func&lt;/li&gt;
&lt;li&gt;array_slice&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don't like prefix your functions with a &lt;code&gt;\&lt;/code&gt; you can import the function with &lt;code&gt;use function&lt;/code&gt; instead and enjoy the benefits of optimized code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'This is my string !'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use a tool like &lt;a href="https://github.com/FriendsOfPHP/PHP-CS-Fixer" rel="noopener noreferrer"&gt;PHP-CS-FIXER&lt;/a&gt; to indicate in your code base which optimisations can be done and fix them, for optimized functions the option is &lt;code&gt;native_function_invocation&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In conclusion, use the optimized functions as much as possible, it does not require much effort and can make your code more efficient.&lt;/p&gt;

&lt;p&gt;Here is some links : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/55854738/when-was-the-strlen-opcode-introduced-in-php" rel="noopener noreferrer"&gt;when strlen was introduced&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/php/php-src/blob/PHP-7.3.8/Zend/zend_compile.c#L3904" rel="noopener noreferrer"&gt;Function optimized in PHP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for reading,&lt;br&gt;
Codeur Malin&lt;/p&gt;

</description>
      <category>php</category>
      <category>webdev</category>
      <category>codequality</category>
      <category>beginners</category>
    </item>
    <item>
      <title>PHP Tips : Pourquoi utiliser "continue" ?</title>
      <dc:creator>Codeur Malin</dc:creator>
      <pubDate>Sat, 11 Apr 2020 18:12:15 +0000</pubDate>
      <link>https://forem.com/codeurm/php-tips-pourquoi-utiliser-continue-2k0c</link>
      <guid>https://forem.com/codeurm/php-tips-pourquoi-utiliser-continue-2k0c</guid>
      <description>&lt;p&gt;Hello world !&lt;/p&gt;

&lt;p&gt;Je vais vous présentez ici un petit tips en PHP mais qui peut facilement être adapté et utilisé dans d'autres langages qui va vous permettre d'avoir un code plus lisible lorsque vous utilisez des conditions à l'intérieur de boucles. &lt;/p&gt;

&lt;p&gt;C'est bien évidemment l'utilisation du mot clé &lt;a href="https://www.php.net/manual/fr/control-structures.continue.php"&gt;continue&lt;/a&gt;, comme indiqué dans le titre !&lt;/p&gt;

&lt;p&gt;Donc &lt;code&gt;continue&lt;/code&gt; est utilisé pour passer à l'itération suivante dans une boucle. &lt;br&gt;
L'avantage premier de ce mot clé est ainsi d'aplatir le code quand il est utilisé avec une &lt;code&gt;condition inversé&lt;/code&gt;. &lt;br&gt;
Souvent il nous arrive d'avoir des conditions à l'intérieur d'une boucle mais la logique qu'on désire effectuer se trouve également dans cette condition. Le souci est alors d'avoir un niveau d'indentation élevé qui pourrait être évité avec l'utilisation de &lt;code&gt;continue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Voici un exemple ci-dessous :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// On veut afficher le nom des héros s'ils sont définis&lt;/span&gt;
&lt;span class="nv"&gt;$heroes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'T Challa'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Tony Stark'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Bruce Wayne'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// sans continue                 // avec continue&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$heroes&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$hero&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$heroes&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$hero&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;          
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hero&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hero&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// condition inversé&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;        &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;                        &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;                            &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;                              &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="o"&gt;...&lt;/span&gt;
                               &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ici on voit qu'en utilisant une &lt;code&gt;condition inversée&lt;/code&gt; + &lt;code&gt;continue&lt;/code&gt;, on a la possibilité de sortir notre logique de la condition et donc d'avoir un niveau d'imbrication en moins. Ainsi, le code devient plus lisible surtout s'il y a plusieurs niveaux d'imbrication.&lt;/p&gt;

&lt;p&gt;Merci d'avoir pris le temps de lire mon premier post 😃&lt;br&gt;
Codeur M&lt;/p&gt;

</description>
      <category>php</category>
      <category>codequality</category>
      <category>beginners</category>
      <category>french</category>
    </item>
  </channel>
</rss>
