<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Michael Para - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Michael Para - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 05 May 2026 19:57:42 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/Michael-para/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How PHP Type Juggling Works – Explained with Code Examples ]]>
                </title>
                <description>
                    <![CDATA[ PHP is a dynamically typed language. This means that variable types are determined at runtime, and you don’t need to explicitly define types when declaring variables. One of PHP’s unique features is type juggling, a concept that can be both fascinati... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-php-type-juggling-works-explained-with-code-examples/</link>
                <guid isPermaLink="false">67fed115c3894cfa21b37d64</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP7 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Para ]]>
                </dc:creator>
                <pubDate>Tue, 15 Apr 2025 21:35:17 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1744752144618/3f40dca7-3148-44fc-8cc0-c10315e706e3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>PHP is a dynamically typed language. This means that variable types are determined at runtime, and you don’t need to explicitly define types when declaring variables.</p>
<p>One of PHP’s unique features is <strong>type juggling</strong>, a concept that can be both fascinating and tricky.</p>
<p>Type juggling happens when PHP automatically converts a variable from one data type to another, depending on how it is being used. While it may save you some effort, it can also lead to unexpected behaviour if you are not careful.</p>
<p>In this article, I will explain what PHP type juggling is, and how it works. In the following sections, you will learn how PHP handles type juggling and see examples to make the concept easier to understand.</p>
<h2 id="heading-what-is-php-type-juggling">What is PHP Type Juggling?</h2>
<p><a target="_blank" href="https://flatcoding.com/tutorials/php/php-type-juggling/">Type juggling</a> refers to PHP’s ability to perform implicit type conversions. Instead of requiring you to declare a variable's type, PHP evaluates the context in which the variable is used and changes its type accordingly. This is a direct result of PHP being dynamically typed.</p>
<p>For instance, if you use a string in a mathematical operation, PHP will try to convert that string into a number. Let’s take a look at a quick example:</p>
<pre><code class="lang-php">$number = <span class="hljs-string">"10"</span>; <span class="hljs-comment">// This is a string</span>
$result = $number + <span class="hljs-number">5</span>; <span class="hljs-comment">// PHP converts $number to an integer</span>
<span class="hljs-keyword">echo</span> $result; <span class="hljs-comment">// Outputs: 15</span>
</code></pre>
<p>Here, <code>$number</code> starts as a string but is treated as an integer during the addition operation. This automatic conversion is what makes PHP type juggling so powerful and, at times, unpredictable.</p>
<h3 id="heading-how-does-php-handle-type-juggling">How Does PHP Handle Type Juggling?</h3>
<p>PHP evaluates <a target="_blank" href="https://flatcoding.com/tutorials/php/php-data-types-php-gettype/">types based on the context of the operation</a>. When juggling types, it follows specific rules for conversions:</p>
<h4 id="heading-strings-to-numbers">Strings to Numbers</h4>
<p>If a string contains a valid numeric value, PHP converts it to a number when needed. For example:</p>
<pre><code class="lang-php"><span class="hljs-keyword">echo</span> <span class="hljs-string">"5"</span> + <span class="hljs-number">10</span>; <span class="hljs-comment">// Outputs: 15</span>
</code></pre>
<p>PHP sees the string "5". It understands it’s a number, and changes it to the number 5 before adding it.</p>
<h4 id="heading-booleans-in-numeric-contexts">Booleans in Numeric Contexts</h4>
<p>In a boolean data type, the <code>true</code> value is treated as <code>1</code>, and <code>false</code> is treated as <code>0</code>. This can lead to unexpected results if you are not paying attention:</p>
<pre><code class="lang-php"><span class="hljs-keyword">echo</span> <span class="hljs-literal">true</span> + <span class="hljs-number">10</span>; <span class="hljs-comment">// Outputs: 11</span>
<span class="hljs-keyword">echo</span> <span class="hljs-literal">false</span> + <span class="hljs-number">10</span>; <span class="hljs-comment">// Outputs: 10</span>
</code></pre>
<p>This is especially dangerous in comparisons:</p>
<pre><code class="lang-php">var_dump(<span class="hljs-literal">false</span> == <span class="hljs-string">""</span>); <span class="hljs-comment">// true</span>
var_dump(<span class="hljs-literal">true</span> == <span class="hljs-string">"1"</span>); <span class="hljs-comment">// true</span>
var_dump(<span class="hljs-literal">false</span> == <span class="hljs-string">"0"</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p>PHP tries to convert both operands to the same type before comparison, which can lead to unexpected results. For example, <code>false == ""</code> is <code>true</code> because both are loosely interpreted as falsy values.</p>
<h4 id="heading-arrays-and-type-conversion">Arrays and Type Conversion</h4>
<p>Arrays cannot be directly converted into strings. If you attempt to do that, PHP will throw an error or a notice depending on the context.</p>
<p>Here is an example:</p>
<pre><code class="lang-php">$array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">echo</span> $array + <span class="hljs-number">5</span>;  
<span class="hljs-keyword">echo</span> $array . <span class="hljs-string">"test"</span>;
</code></pre>
<p>Here is the output with a fatal error:</p>
<pre><code class="lang-bash">Fatal error: Uncaught TypeError: Unsupported operand types: array + int <span class="hljs-keyword">in</span> /var/www/test.php:3
Stack trace:
<span class="hljs-comment">#0 {main}</span>
  thrown <span class="hljs-keyword">in</span> /var/www/test.php on line 3
</code></pre>
<p>This because it is trying to use arrays in arithmetic or string operations, which doesn’t work like it does with other types. Instead, you need to explicitly convert them using functions like <code>count()</code> or <code>implode()</code>, depending on what you're trying to achieve:</p>
<pre><code class="lang-php">$array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">echo</span> count($array) + <span class="hljs-number">5</span>; <span class="hljs-comment">// Outputs: 8</span>
</code></pre>
<p>In the following section, we will explore some examples associated with type juggling to help you avoid potential bugs in your code.</p>
<h2 id="heading-type-juggling-examples">Type Juggling Examples</h2>
<h3 id="heading-loose-comparisons">Loose Comparisons (<code>==</code>)</h3>
<p>PHP’s loose comparison operator (<code>==</code>) uses type juggling to compare values. This can lead to results that might not align with your expectations:</p>
<pre><code class="lang-php">var_dump(<span class="hljs-number">0</span> == <span class="hljs-string">"0"</span>); <span class="hljs-comment">// true</span>
var_dump(<span class="hljs-number">0</span> == <span class="hljs-string">""</span>); <span class="hljs-comment">// true</span>
var_dump(<span class="hljs-string">"123abc"</span> == <span class="hljs-number">123</span>); <span class="hljs-comment">// true</span>
</code></pre>
<p>In this example, PHP converts <code>"123abc"</code> to the number <code>123</code> because of the loose comparison, even though <code>"abc"</code> is not numeric.</p>
<h4 id="heading-strict-comparisons-as-a-solution">Strict Comparisons (<code>===</code>) as a Solution</h4>
<p>To avoid the problems caused by loose comparisons, use strict comparisons (<code>===</code>). These compare both value and type:</p>
<pre><code class="lang-php">var_dump(<span class="hljs-number">0</span> === <span class="hljs-string">"0"</span>); <span class="hljs-comment">// false</span>
var_dump(<span class="hljs-number">123</span> === <span class="hljs-string">"123"</span>); <span class="hljs-comment">// false</span>
</code></pre>
<p>Strict comparisons ensure that the types are not juggled, reducing the risk of unexpected behavior.</p>
<p>So the question is, how can you handle type juggling safely? This is what you’ll learn in the following section.</p>
<h2 id="heading-how-to-handle-type-juggling-safely">How to Handle Type Juggling Safely</h2>
<h3 id="heading-use-explicit-type-casting">Use Explicit Type Casting</h3>
<p>If you want a variable to be a certain type (like an integer or a float), convert it directly instead of letting PHP guess. This avoids unexpected behavior.</p>
<pre><code class="lang-php">$input = <span class="hljs-string">"42cats"</span>;
$cleanNumber = (<span class="hljs-keyword">int</span>)$input;

<span class="hljs-keyword">echo</span> $cleanNumber + <span class="hljs-number">10</span>; <span class="hljs-comment">// Outputs: 52</span>
</code></pre>
<p>PHP turns "42cats" into 42. PHP would do this even without casting, but casting shows clearly what you want and keeps behavior consistent.</p>
<p>Note: Any non-empty string (except "0") becomes <code>true</code> when cast to a boolean.</p>
<h3 id="heading-validate-input-before-use">Validate Input Before Use</h3>
<p>Always check that input data is the type you expect, especially if it comes from users or outside sources.</p>
<pre><code class="lang-php">$price = $_POST[<span class="hljs-string">'price'</span>] ?? <span class="hljs-string">''</span>;

<span class="hljs-keyword">if</span> (is_numeric($price)) {
    <span class="hljs-keyword">echo</span> $price + <span class="hljs-number">10</span>;
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Please enter a valid number."</span>;
}
</code></pre>
<p>A string like <code>"abc"</code> would turn into <code>0</code> without this check, and you'd get <code>10</code>—which is wrong and misleading.</p>
<p>Here, you have to check if the input is an array:</p>
<pre><code class="lang-php">$data = $_POST[<span class="hljs-string">'items'</span>] ?? [];

<span class="hljs-keyword">if</span> (is_array($data)) {
    <span class="hljs-keyword">echo</span> count($data);
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Invalid data format."</span>;
}
</code></pre>
<p>This prevents errors when PHP tries to use a string or number as an array.</p>
<h3 id="heading-prefer-strict-comparisons">Prefer Strict Comparisons (===)</h3>
<p>Loose comparisons (<code>==</code>) let PHP convert types when comparing values. This can cause mistakes.</p>
<pre><code class="lang-php">var_dump(<span class="hljs-number">0</span> == <span class="hljs-string">"0"</span>);    <span class="hljs-comment">// true</span>
var_dump(<span class="hljs-number">0</span> == <span class="hljs-string">""</span>);     <span class="hljs-comment">// false (not expected)</span>
var_dump(<span class="hljs-string">"abc"</span> == <span class="hljs-number">0</span>);  <span class="hljs-comment">// false</span>
</code></pre>
<p>PHP turns both sides into numbers, so <code>"abc"</code> becomes <code>0</code>. That’s usually not what you want.</p>
<p>To solve that issue, use strict comparisons (<code>===</code>) to check both the value and the type:</p>
<pre><code class="lang-php">var_dump(<span class="hljs-number">0</span> === <span class="hljs-string">"0"</span>);     <span class="hljs-comment">// false</span>
var_dump(<span class="hljs-string">"123"</span> === <span class="hljs-number">123</span>); <span class="hljs-comment">// false</span>
</code></pre>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>PHP type juggling is a double-edged sword. On one hand, it allows for flexibility and faster coding, but on the other, it can lead to subtle bugs if you are not cautious.</p>
<p>By understanding how type juggling works and following best practices like strict comparisons, explicit casting, and input validation, you can make your code safer and more predictable.</p>
<p>Stay tuned for my next article. You can explore more helpful PHP tutorials on my blog, <a target="_blank" href="https://flatcoding.com/">FlatCoding</a>. You can also check the <a target="_blank" href="https://www.php.net/manual/en/">PHP manual</a> for more details. Thank you for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Logical Operators in PHP – A Beginner's Guide ]]>
                </title>
                <description>
                    <![CDATA[ Logical operators play a key role in programming languages. They let you manipulate boolean values and evaluate logical conditions. In PHP, there are four fundamental logical operators: AND, OR, NOT, and XOR. This guide will help you understand these... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/logical-operators-in-php/</link>
                <guid isPermaLink="false">66d46040b3016bf139028d61</guid>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Para ]]>
                </dc:creator>
                <pubDate>Tue, 30 May 2023 17:35:08 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/luca-bravo-XJXWbfSo2f0-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Logical operators play a key role in programming languages. They let you manipulate boolean values and evaluate logical conditions.</p>
<p>In PHP, there are four fundamental logical operators: AND, OR, NOT, and XOR. This guide will help you understand these operators, and I'll explain how they work using code examples and practical use cases.</p>
<h2 id="heading-the-logical-and-operator-ampamp">The Logical AND Operator (&amp;&amp;)</h2>
<p>The AND operator, written like “&amp;&amp;,” evaluates to true only if both of its operands are true. It evaluates to false if any of the operands are false, resulting in a false outcome.</p>
<p>This operator is commonly used to combine multiple conditions in an if statement or a loop. It helps ensure that all conditions are satisfied for the overall condition to be true.</p>
<pre><code class="lang-php">
<span class="hljs-comment">// Checking if two conditions are true using the AND operator</span>
$mx = <span class="hljs-number">5</span>;
$my = <span class="hljs-number">10</span>;

<span class="hljs-keyword">if</span> ($mx &gt; <span class="hljs-number">0</span> &amp;&amp; $my &gt; <span class="hljs-number">0</span>) {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Both conditions are true!"</span>;
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"This condition is false."</span>;
}
</code></pre>
<p>In the above example, the AND operator verifies that both <code>$x</code> and <code>$y</code> are greater than 0.</p>
<p>So, if both conditions are true, the code inside the if block will execute, displaying “Both conditions are true!”. Alternatively, when the else block is triggered, it suggests that one or more of the conditions are false.</p>
<p>Let's now shift our focus to the counterpart of the AND operator – the OR operator.</p>
<h2 id="heading-the-logical-or-operator">The Logical OR Operator (||)</h2>
<p>The <a target="_blank" href="https://codedtag.com/php/php-or-operator/">PHP OR</a> operator, written like “||”, returns true if at least one of its operands is true. It evaluates to false only when both operands are false.</p>
<p>You can use this operator when you want to execute a block of code if any of several conditions are satisfied.</p>
<pre><code class="lang-php">
<span class="hljs-comment">// Checking if at least one condition is true using the OR operator</span>
$mx = <span class="hljs-number">5</span>;
$my = <span class="hljs-number">10</span>;

<span class="hljs-keyword">if</span> ($mx &gt; <span class="hljs-number">0</span> || $my &gt; <span class="hljs-number">0</span>) {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"At least one condition is true!"</span>;
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Both conditions are false."</span>;
}
</code></pre>
<p>In this example, the OR operator checks if either <code>$x</code> or <code>$y</code> (or both) are greater than 0. If any of the conditions is true, the code inside the if block will execute, displaying “At least one condition is true!”.</p>
<p>Otherwise, the else block will execute, indicating that both conditions are false.</p>
<p>Now let's explore the NOT operator and understand how it works.</p>
<h2 id="heading-the-logical-not-operator">The Logical NOT Operator (!)</h2>
<p>The NOT operator, written like "!", is a unary operator that inverses the value of its operand. When the operand is false, it will return true. cvonversely, when the operand is true, it will return false.</p>
<p>This operator is commonly utilized to invert a condition or verify the absence of a specific state.</p>
<pre><code class="lang-php">
<span class="hljs-comment">// Checking if a condition is false using the NOT operator</span>
$x = <span class="hljs-number">5</span>;

<span class="hljs-keyword">if</span> (!($x &gt; <span class="hljs-number">10</span>)) {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Condition is false!"</span>;
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Condition is true."</span>;
}
</code></pre>
<p>In the above example, the NOT operator negates the result of the condition <code>$x &gt; 10</code>. If the condition is false (which it is in this case), the code inside the if block will execute, displaying “Condition is false!”. If the condition is found to be true, the execution of the else block confirms the validity of the condition.</p>
<p>Finally, let's delve deeper into the XOR operator in PHP and gain a better understanding of its usage and behavior.</p>
<h2 id="heading-the-logical-xor-operator-exclusive-or">The Logical XOR Operator (Exclusive OR)</h2>
<p>Although PHP doesn't have a specific XOR operator, we can simulate XOR behavior using a combination of other logical operators. XOR returns true if exactly one of the operands is true, while it returns false if both operands are either true or false.</p>
<pre><code class="lang-php"><span class="hljs-comment">// XOR operator implementation using AND, OR, and NOT operators</span>
$x = <span class="hljs-literal">true</span>;
$y = <span class="hljs-literal">false</span>;

<span class="hljs-keyword">if</span> (($x || $y) &amp;&amp; !($x &amp;&amp; $y)) {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Exactly one condition is true (XOR)!"</span>;
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">echo</span> <span class="hljs-string">"Both conditions are either true or false."</span>;
}
</code></pre>
<p>In this example, we create an XOR behavior by checking if either <code>$x</code> or <code>$y</code> is true (<code>$x || $y</code>) and ensuring that both conditions are not true at the same time (<code>!($x &amp;&amp; $y)</code>).</p>
<p>If exactly one condition is true, the code inside the if block will execute, displaying “Exactly one condition is true (XOR)!” Otherwise, the else block will execute, indicating that both conditions are either true or false.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p><a target="_blank" href="https://codedtag.com/php/php-logical-operators/">PHP logical operators</a> are powerful tools in PHP that allow us to manipulate boolean values and evaluate logical conditions. Understanding the functionality and usage of logical operators is essential for building reliable and efficient PHP programs.</p>
<p>By mastering these operators, you can create complex conditional statements and make your code more robust and flexible.</p>
<p>In this article, we explored the four fundamental logical operators in PHP: AND, OR, NOT, and XOR.</p>
<p>We provided explanations, code examples, and practical use cases to demonstrate their functionalities. By applying these operators effectively, you can perform intricate logical operations, control the flow of your programs, and make informed decisions based on various conditions.</p>
<p>Remember to practice implementing logical operators in PHP and experiment with different scenarios to deepen your understanding.</p>
<p>Thank you for reading, If you'd like to read more of my articles, you can find them on <a target="_blank" href="https://flatcoding.com/">FlatCoding</a>. Stay tuned for my next articles.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Python? How the Interpreter Works and How to Write "Hello World" in Python ]]>
                </title>
                <description>
                    <![CDATA[ In this article, I am going to explain what Python is and how the Python interpreter works. Then you'll write your first "Hello World" program. What is Python? Python is a high-level programming language designed to do many tasks. It's based on the C... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-python-beginners-guide/</link>
                <guid isPermaLink="false">66d46044b6b7f664236cbe14</guid>
                
                    <category>
                        <![CDATA[ beginner ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Para ]]>
                </dc:creator>
                <pubDate>Mon, 17 Oct 2022 13:38:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/python-img.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, I am going to explain what Python is and how the Python interpreter works. Then you'll write your first "Hello World" program.</p>
<h2 id="heading-what-is-python">What is Python?</h2>
<p>Python is a high-level programming language designed to do many tasks. It's based on the CPython interpreter which translates the Python code into something the machine can read.</p>
<p>Python gives us the ability to use a lot of modules and packages with our code, which are standard libraries built in with the interpreter.</p>
<p>You can use Python to do many tasks such as:</p>
<ul>
<li><p>Machine Learning</p>
</li>
<li><p>Artificial Intelligence</p>
</li>
<li><p>Data Visualization</p>
</li>
<li><p>Programming Applications</p>
</li>
<li><p>Web Applications</p>
</li>
<li><p>Language and Game Development</p>
</li>
<li><p>Data Analytics</p>
</li>
</ul>
<p>and more.</p>
<p>Additionally, Python's syntax is pretty simple and easy to learn – often it seems that you are just writing a message to someone else. Just make sure you know the indentation rules :).</p>
<p>We can compare Python with other interpreted programming languages such as Java, JavaScript, PHP, and others. But you might be wondering – what is CPython?</p>
<p>In the following section, I am going to focus on the history of the Python interpreter in-depth, then I'll answer this question.</p>
<h2 id="heading-python-history-overview">Python History Overview</h2>
<p>The first appearance of the Python programming language was in late 1980s. It was created by Guido van Rossum.</p>
<p>Python was designed to replace the ABC programming language which worked with Amoeba operating system.</p>
<p>Rossum started the implementation in 1989 and he worked on Python alone until 2018.</p>
<p>He named it Python because the first version of it was able to read the BBC comedy script “Monty Python's Flying Circus”.</p>
<p>The first release was in 1994 under version 1.0 (Python 1.0) and the second release was in 2000, named version 2.0.</p>
<p>In version 2.0, van Rossum added minor features such as collection systems and comprehensions.</p>
<p>The third version was released in 2008 and fixed a basic flaw of the language. They named this version “Py3K”, or Python 3.0.</p>
<h2 id="heading-how-does-the-python-interpreter-work">How Does the Python Interpreter Work?</h2>
<p>The Python interpreter is called “CPython” and it's written in the C programming language. This is the default implementation for Python.</p>
<p>In the following sections, you will understand how the Python interpreter works behind the scenes.</p>
<h3 id="heading-source-code-analysis">Source Code Analysis</h3>
<p>Actually, any translator starts with the source code analysis. Here the Python interpreter receives the source code and initializes some instructions to do the following things:</p>
<p>It follows the indentation rule and checks the Python syntax. Maybe there are some incorrect lines, so it will stop the program from the execution to show the error message.</p>
<p>This phase is called <a target="_blank" href="https://codedtag.com/php/what-is-php-how-to-write-php-program/#the-lexical-analysis">lexical analysis</a>, which means dividing the source code files into a list of tokens</p>
<p>In the following step, the interpreter will generate byte codes. Let's see how that works.</p>
<h3 id="heading-byte-code-generation">Byte Code Generation</h3>
<p>Once the parser of the Python interpreter receives the tokens, it starts to manipulate the lexical tokens. It generates a big structure called the AST (Abstract Syntax Tree).</p>
<p>The interpreter converts this AST to byte code which means machine language. In Python, the byte code can be saved in a file ending with the “.pyc” extension.</p>
<p>In the following section, you will see how the python interpreter executes these byte codes.</p>
<h3 id="heading-the-python-virtual-machine-pvm">The Python Virtual Machine (PVM)</h3>
<p>The Python interpreter initializes its runtime engine called PVM which is the Python virtual machine.</p>
<p>The interpreter loads the machine language with the library modules and inputs it into the PVM. This converts the byte code into executable code such as 0s and 1s (binary).</p>
<p>And then it prints the results.</p>
<p>Note that if an error happens during the PVM process, the executor will terminate the operation immediately to display the error.</p>
<p>Now you will learn how to install Python on your operating system.</p>
<p>If you have no Python software or you're using a mobile device, you can use any <a target="_blank" href="https://codedtag.com/python/free-online-python-compiler-interpreter/">online Python compiler</a>.</p>
<h2 id="heading-how-to-install-python">How to Install Python</h2>
<p>To install Python on your Ubuntu Linux operating system, follow these instructions:</p>
<p>Open your terminal and run the following command to update the Ubuntu local system repository:</p>
<pre><code class="lang-xml">sudo apt update
</code></pre>
<p>Install the latest version of Python using the following command:</p>
<pre><code class="lang-xml">sudo apt install python3
</code></pre>
<p>If you are using Windows OS, you have to follow these steps to install Python on your machine.</p>
<ol>
<li><p>Navigate to the <a target="_blank" href="https://www.python.org/downloads/windows/">python official page</a> and download the latest installer.</p>
</li>
<li><p>Once you choose the latest version by the above link, you have to select the bit system according to your Windows operating system.</p>
</li>
<li><p>Run the installer and follow the written instruction on the installer.</p>
</li>
</ol>
<p>Once you install the program, you have to verify the current version of Python on your operating system by using the following command via terminal or CMD according to your operating system.</p>
<p>Just type <code>python</code> and hit enter – it will show you the result like in the below image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/image-67.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Verifying Python Version Via CMD</em></p>
<p>In the next section, you will learn how to write your first program with Python.</p>
<h2 id="heading-how-to-write-your-first-python-program">How to Write Your First Python Program</h2>
<p>In this program, you're going to print the classic “Hello World” message using the Python programming language.</p>
<p>First, create a folder and name it “CodedTag” then create a file inside and name it as a “page.py”.</p>
<p>Then copy and paste the following Python code:</p>
<pre><code class="lang-python"><span class="hljs-comment"># output: Hello World</span>
print( <span class="hljs-string">"Hello World"</span> )
</code></pre>
<p>Then open the terminal and navigate to the project directory and run the following command:</p>
<pre><code class="lang-xml">python page.py
</code></pre>
<p>The output will be like the following image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/image-68.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Execute Python Message</em></p>
<p>Congratulations – you just wrote your first Python program.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, you learned what Python is and a bit of its history. You also learned how the Python interpreter works.</p>
<p>Let's summarize it in a few points:</p>
<ol>
<li><p>The interpreter checks and searches for syntax errors and verifies indentation rules. Then it converts the source code via tokenization.</p>
</li>
<li><p>The parser receives the lexical tokens and generates an Abstract Syntax Tree.</p>
</li>
<li><p>The interpreter converts the AST to Byte Code and initializes the Python Virtual machine to execute the byte code and send back the final result.</p>
</li>
</ol>
<p>Thank you for reading, If you'd like to read more of my articles, you can find them on <a target="_blank" href="https://flatcoding.com/">FlatCoding</a>. Stay tuned for my next articles.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is PHP? How to Write Your First PHP Program ]]>
                </title>
                <description>
                    <![CDATA[ In this article, you will learn what the PHP programming language is and how to write your first program with it. History of PHP PHP is the most used and popular scripting language generated for web development. You can embed it in HTML documents. PH... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-php-write-your-first-php-program/</link>
                <guid isPermaLink="false">66d46042d7a4e35e38434997</guid>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Michael Para ]]>
                </dc:creator>
                <pubDate>Wed, 03 Aug 2022 11:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/07/Untitled-2-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, you will learn what the PHP programming language is and how to write your first program with it.</p>
<h2 id="heading-history-of-php">History of PHP</h2>
<p>PHP is the most used and popular scripting language generated for web development. You can embed it in HTML documents.</p>
<p>PHP is written in the high-level C programming language. The first generation of PHP was PHP/FI created in 1994 by Rasmus Lerdorf. He wrote it to track visitors to his resume.</p>
<p>The thing that allowed him to easily create the first home page with PHP was the ability to embed the PHP code within HTML markup.</p>
<p>The second generation was released as PHP/FI Version 2 in 1995 which referred to Personal Home Page Tools. At this time PHP depended on a small parser engine to translate and understand a few special instructions and some utilities that were used on the PHP personal home page.</p>
<p>PHP was officially born and become more widely used in 1996. In the beginning, it was being used on more than 15,000 web applications around the world. That number increased to 50,000 the following year.</p>
<p>Currently, PHP is fully dependent on an advanced interpreter called the Zend Engine. To learn more about <a target="_blank" href="https://codedtag.com/php/what-is-php-write-a-program/">what PHP is and how to write an advanced PHP program</a> you should read more about its syntax.</p>
<p>As I mentioned before, PHP depends on the Zend Engine interpreter. But the question is, what is an interpreter? And how it does work?</p>
<p>In the next section, I'll explain everything from scratch – from the source code to the PHP server response. But before that you have to know the difference between the interpreter and the compiler.</p>
<p>Let's dive right in.</p>
<h2 id="heading-whats-the-difference-between-an-interpreter-and-a-compiler">What's the Difference Between an Interpreter and a Compiler?</h2>
<p>The interpreter is a program that takes the source code line by line and translates it into binary bits (0s and 1s) – machine language. During this process, the developer can edit the source code.</p>
<p>It doesn't take long for the interpreter to analyze the code – such as deleting the comments from the source code, whitespaces, and so on. But the overall time for execution is a bit slower.</p>
<p>On the other hand, the compiler is a program that takes the full source code that's already written in a high-level programming language and translates it into binary or machine language.</p>
<p>During this process, you can't edit the source code because it goes in as one piece to the compiler. The compiler is slow to analyze code but translates very quickly.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/WhatsApp-Image-2022-07-27-at-2.34.06-PM.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's take a more in-depth look at the PHP interpreter to see how it works.</p>
<h2 id="heading-how-does-the-php-interpreter-work">How Does the PHP Interpreter Work?</h2>
<p>As I mentioned before, the PHP interpreter is called the Zend Engine and it has four phases during which it interprets the PHP source code – in this section, we are going to dive more into each phase.</p>
<h3 id="heading-lexical-analysis">Lexical Analysis</h3>
<p>The PHP interpreter takes the source code from the server and starts the first phase called lexical analysis (or tokenization). In this process, the interpreter removes all whitespaces and comment syntax, searches for any errors in the source code, and then generates a token sequence.</p>
<p>The lexical analysis does not cause any errors during this stage because it is only responsible for producing a token sequence. But it throws a fatal parse error to stop this phase directly if it finds any error in the source code.</p>
<h3 id="heading-the-parser">The Parser</h3>
<p>In the following step the parser takes over. In this phase, the parser receives the token sequence and sets some of the instructions to create the Zend Engine VM (Virtual Machine) – which is similar to assembly language – to manipulate the token sequence that was already created with the previous stage.</p>
<h3 id="heading-the-compilation">The Compilation</h3>
<p>This phase is already under the parser stage, and here the parser is starting the compilation by generating the AST (Abstract Syntax Tree) – then passing it to the code generator.</p>
<p>The output of the compilation is an intermediate code that already depends on the Zend Engine VM. This is known as Operation Codes (OPCodes). The Opcodes contain some of the instructions to perform all the operations which require the implementation of flow control.</p>
<h3 id="heading-the-execution">The Execution</h3>
<p>This is the last phase, and here the executor receives the intermediate code that was already generated by the previous stage. It can read these OPCodes from the array of the instructions and then execute them one by one.</p>
<p>Overall, the Zend Engine has two separated functions, compiling and executing, which are zend_compile and zend_execute.</p>
<p>In the next section, you are going to write your first PHP program! But before you do that, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-started-with-php/">you have to install a Wamp (for Windows) or XAMPP (for Linux/MacOS) server</a> depending on which operating system you use.</p>
<h2 id="heading-how-to-install-xampp">How to Install XAMPP</h2>
<p>In this section, I'll explain the XAMPP server and how to run the PHP server on your local machine.</p>
<p>Firstly, XAMPP is a free software used to create a PHP web server. But What does XAMPP mean?</p>
<ol>
<li><p>"X" refers to <strong>Operating Systems</strong> such as Windows, Linux, or macOS. So that means we can install the XAMPP server on one of the operating systems we mentioned in this line.</p>
</li>
<li><p>"A" refers to <strong>Apache</strong>, and that is the PHP webserver software.</p>
</li>
<li><p>"M" refers to <strong>MariaDB - MySQL</strong>, the database management systems.</p>
</li>
<li><p>"P" refers to <strong>PHP</strong> (Personal Home Page) – the server-side scripting language that helps us create dynamic web pages.</p>
</li>
<li><p>"P" refers to <strong>Perl</strong> which is used in web development, network programming, or system administration.</p>
</li>
</ol>
<p>So XAMPP refers to all the packages that you need to do web application development.</p>
<p>To install the XAMPP server on your local machine, navigate to the <a target="_blank" href="https://www.apachefriends.org/">XAMPP official page</a> and download the installer according to your operating system.</p>
<p>Once you've download it, just install the program according to the instructions you read in the installer.</p>
<p>The final result should look like the below image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The XAMPP Control Panel</em></p>
<p>You only have to click on the "start" button beside the Apache module to run the PHP server.</p>
<p>Let's explore the important folders inside the XAMPP server app.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>XAMPP Important Folders</em></p>
<p>The above image shows you all the important folders, but we only need to focus on the "<strong>htdocs</strong>" folder. This folder is the public directory that contains all PHP projects.</p>
<p>So you'll put any new PHP project inside the "<strong>htdocs</strong>" folder. And to open the result on the web browser, you just need to navigate to "<strong>localhost/your_project_folder_name</strong>".</p>
<p>Let's write a PHP program to clarify that.</p>
<h2 id="heading-how-to-write-your-first-php-program">How to Write Your First PHP Program</h2>
<p>To help you write your first PHP program, we're just going to print a small message – "Hello World".</p>
<p>Firstly, make sure your PHP server is running on your local machine – I am using the XAMPP server on my local machine.</p>
<p>Second, create a folder inside your server app directory and name it <a target="_blank" href="http://codedtag.com/">codedtag</a>.</p>
<p>The below image shows you that my public folder in the XAMPP server app is (<strong>htdocs</strong>) on Windows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/image-273.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The public folder of the XAMPP server</em></p>
<p>For the next step, create an index page that ends with a PHP extension. Inside the "codedtag" folder, copy-paste the following PHP code:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span> 
   <span class="hljs-keyword">echo</span> <span class="hljs-string">"Hello World"</span>;
<span class="hljs-meta">?&gt;</span>
</code></pre>
<p>To run the script, open the browser and navigate to <strong>localhost/codedtag</strong>. You will see the print message like the below image:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/image-274.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The PHP Print Message</em></p>
<p>And that's it! You've printed your first PHP program.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, we discussed what PHP is and summarized its history in a few lines. We also learned the difference between the compiler and the interpreter.</p>
<p>Also, we discussed the exact steps of how the PHP interpreter works. To summarize, let’s have a look at the PHP Zend Engine from the top.</p>
<ol>
<li><p>The first step is lexical analysis. In this stage, the interpreter deletes all whitespaces and comments from the source code and generates a token sequence.</p>
</li>
<li><p>The next step is called the parser, and here the parser sets the instructions to create the Zend Engine VM to manipulate the token sequence.</p>
</li>
<li><p>The compilation stage creates and passes the AST (Abstract Syntax Tree) to the code generator and the final compilation output is OPCodes.</p>
</li>
<li><p>The following step is for the executor, and in this stage the executor is reading and executing the instructions from the array.</p>
</li>
</ol>
<p>If you want to learn more about PHP, here's a <a target="_blank" href="https://www.freecodecamp.org/news/the-php-handbook/">full handbook that covers all the basics in depth</a>.</p>
<p>Stay tuned for my next article. You can read more of my articles on <a target="_blank" href="https://flatcoding.com/">FlatCoding</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
