<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Farid Mia on Medium]]></title>
        <description><![CDATA[Stories by Farid Mia on Medium]]></description>
        <link>https://medium.com/@mdfarid7830?source=rss-64ecb126d05f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PAyQlmvpBXKMtDFv</url>
            <title>Stories by Farid Mia on Medium</title>
            <link>https://medium.com/@mdfarid7830?source=rss-64ecb126d05f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:18:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mdfarid7830/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unlocking the Power of Short-Circuiting in JavaScript]]></title>
            <link>https://medium.com/@mdfarid7830/unlocking-the-power-of-short-circuiting-in-javascript-a8125ce29b64?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8125ce29b64</guid>
            <category><![CDATA[coding-tips]]></category>
            <category><![CDATA[logicaloperators]]></category>
            <category><![CDATA[javascript-operators]]></category>
            <category><![CDATA[javascript-codes]]></category>
            <category><![CDATA[short-circuiting]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Sun, 08 Dec 2024 17:55:37 GMT</pubDate>
            <atom:updated>2024-12-08T17:55:37.879Z</atom:updated>
            <content:encoded><![CDATA[<p>Short-circuiting is one of JavaScript’s most elegant features, allowing you to simplify conditional logic and make your code cleaner. Whether you’re setting defaults or running conditional operations, the || (OR) and &amp;&amp; (AND) operators can save the day. Let’s explore how they work with practical examples.</p><p><strong>What is Short-Circuiting?</strong></p><p>Short-circuiting happens when JavaScript evaluates logical expressions and stops as soon as the result is determined. It skips unnecessary checks, making your code faster and more efficient.</p><p><strong>The </strong><strong>|| Operator: Returning the First Truthy Value</strong></p><p>The OR operator (||) evaluates values from left to right and <strong>returns the first truthy value</strong>. If none are truthy, it returns the last value.</p><pre>console.log(3 || &#39;Jonas&#39;); // Output: 3 (truthy, so it stops here)<br>console.log(&#39;&#39; || &#39;Jonas&#39;); // Output: &#39;Jonas&#39; (&#39;&#39; is falsy, moves to next)<br>console.log(undefined || 0 || &#39;&#39; || &#39;Hello&#39; || 23 || null); // Output: &#39;Hello&#39; (first truthy)</pre><p>Real-World Use Case: Setting Default Values</p><pre>restaurant.numGuests = 0;<br>const guests = restaurant.numGuests || 10;<br>console.log(guests); // Output: 10 (because 0 is falsy, defaults to 10)</pre><h3>The &amp;&amp; Operator: Returning the First Falsy Value</h3><p>The AND operator (&amp;&amp;) evaluates values from left to right and <strong>returns the first falsy value</strong>. If all values are truthy, it returns the last one.</p><pre>console.log(0 &amp;&amp; &#39;Jonas&#39;); // Output: 0 (first falsy value)<br>console.log(7 &amp;&amp; &#39;Jonas&#39;); // Output: &#39;Jonas&#39; (both truthy, returns last value)<br>console.log(&#39;Hello&#39; &amp;&amp; 23 &amp;&amp; null &amp;&amp; &#39;Jonas&#39;); // Output: null (first falsy value)</pre><p>Real-World Use Case: Conditional Function Calls</p><pre>if (restaurant.orderPizza) {<br>  restaurant.orderPizza(&#39;mushrooms&#39;, &#39;spinach&#39;);<br>}<br>// Same logic, shorter:<br>restaurant.orderPizza &amp;&amp; restaurant.orderPizza(&#39;mushrooms&#39;, &#39;spinach&#39;);</pre><h3>Final Thoughts</h3><p>Short-circuiting is like having a built-in shortcut in your code. It not only saves you time but also keeps your logic easy to read and maintain. Start using || and &amp;&amp; in your code today, and see how they transform your JavaScript! 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8125ce29b64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP 8.4: New Features]]></title>
            <link>https://medium.com/@mdfarid7830/php-8-4-new-features-b02802e696b7?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b02802e696b7</guid>
            <category><![CDATA[php-8]]></category>
            <category><![CDATA[phpunit]]></category>
            <category><![CDATA[php-development]]></category>
            <category><![CDATA[php-developers]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Fri, 22 Nov 2024 04:44:50 GMT</pubDate>
            <atom:updated>2024-11-22T04:44:50.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTwWRyWZdv6EpcxE75-_WA.png" /></figure><ol><li>Enhanced Property Accessors</li></ol><p>Property accessors (get and set) allow developers to define custom logic for property access and assignment.</p><pre>class Temperature<br>{<br>    private float $celsius;<br><br>    public float $fahrenheit<br>    {<br>        get =&gt; $this-&gt;celsius * 9 / 5 + 32;<br>        set (float $fahrenheit) {<br>            $this-&gt;celsius = ($fahrenheit - 32) * 5 / 9;<br>        }<br>    }<br><br>    public function __construct(float $celsius)<br>    {<br>        $this-&gt;celsius = $celsius;<br>    }<br>}<br><br>$temperature = new Temperature(25);<br>echo $temperature-&gt;fahrenheit; // 77<br>$temperature-&gt;fahrenheit = 104;<br>echo $temperature-&gt;fahrenheit; // 104</pre><p>2. Readonly Properties with Initialization</p><p>With private(set), properties can be made read-only but still initialized or modified within the class.</p><pre>class BankAccount<br>{<br>    public private(set) float $balance = 0;<br><br>    public function deposit(float $amount): void<br>    {<br>        $this-&gt;balance += $amount;<br>    }<br>}<br><br>$account = new BankAccount();<br>$account-&gt;deposit(500);<br>echo $account-&gt;balance; // 500<br>// $account-&gt;balance = 1000; // Error: Cannot modify readonly property</pre><p><strong>Real-Life Use Case:</strong><br>Perfect for tracking financial transactions while preventing external modification.</p><p>3. Deprecation Attribute</p><p>Mark outdated methods with a clear deprecation warning and a replacement method.</p><pre>class Logger<br>{<br>    #[\Deprecated(<br>        message: &quot;Use logMessage() instead&quot;,<br>        since: &quot;8.4&quot;,<br>    )]<br>    public function log(string $message): void<br>    {<br>        $this-&gt;logMessage($message);<br>    }<br><br>    public function logMessage(string $message): void<br>    {<br>        echo &quot;[LOG]: $message\n&quot;;<br>    }<br>}<br><br>$logger = new Logger();<br>$logger-&gt;log(&quot;This is a test log.&quot;);</pre><p>4. DOM Query Enhancements</p><p>The DOM module introduces new methods for querying and manipulating HTML documents.</p><pre>$dom = Dom\HTMLDocument::createFromString(<br>    &lt;&lt;&lt;HTML<br>        &lt;div&gt;<br>            &lt;p&gt;Welcome to PHP 8.4&lt;/p&gt;<br>            &lt;p class=&quot;highlight&quot;&gt;This release is exciting!&lt;/p&gt;<br>        &lt;/div&gt;<br>    HTML<br>);<br><br>$node = $dom-&gt;querySelector(&#39;p.highlight&#39;);<br>echo $node-&gt;textContent; // This release is exciting!</pre><p>5. Improved array_find Functionality</p><p>Easily search arrays for specific elements using array_find.</p><pre>$products = [&#39;apple&#39;, &#39;banana&#39;, &#39;carrot&#39;, &#39;date&#39;];<br>$fruit = array_find(<br>    $products,<br>    fn (string $product) =&gt; str_starts_with($product, &#39;b&#39;)<br>);<br><br>echo $fruit; // banana</pre><p>6. Enhanced BcMath Number Handling</p><p>Perform mathematical operations with precision using Number objects.</p><pre>use BcMath\Number;<br><br>$price = new Number(&#39;19.99&#39;);<br>$tax = new Number(&#39;1.50&#39;);<br>$total = $price + $tax;<br><br>echo $total; // &#39;21.49&#39;</pre><h3>Summary</h3><p>PHP 8.4 simplifies and modernizes how developers interact with their code. Key highlights include property accessors, deprecation attributes, enhanced DOM methods, and functional array and database operations upgrades. These features improve performance and align PHP with modern programming practices, making it even more developer-friendly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b02802e696b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Key JavaScript Function Concepts Explained”]]></title>
            <link>https://medium.com/@mdfarid7830/key-javascript-function-concepts-explained-07a33bf4cea0?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/07a33bf4cea0</guid>
            <category><![CDATA[javascript-call]]></category>
            <category><![CDATA[higher-order-function]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learn-javascript]]></category>
            <category><![CDATA[javascript-closure]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Thu, 21 Nov 2024 17:54:17 GMT</pubDate>
            <atom:updated>2024-11-22T08:53:58.953Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript functions offer incredible flexibility, enabling developers to tackle problems efficiently. Here’s a concise exploration of some key concepts:</p><ol><li><strong>Default Parameters</strong></li></ol><p>Default parameters allow setting fallback values for function arguments, simplifying code, and enhancing readability.</p><pre>const createBooking = function (flightNum, numPassengers = 1, price = 199 * numPassengers) {<br>  const booking = { flightNum, numPassengers, price };<br>  console.log(booking);<br>};<br>createBooking(&#39;LH123&#39;); // { flightNum: &#39;LH123&#39;, numPassengers: 1, price: 199 }</pre><p>2. <strong>Passing Arguments by Value vs. Reference</strong></p><p>JavaScript passes primitive values by <strong>value</strong> and objects by <strong>reference</strong>. Mutating an object inside a function alters the original object.</p><pre>const checkIn = function (flightNum, passenger) {<br>  flightNum = &#39;LH999&#39;;<br>  passenger.name = &#39;Mr. &#39; + passenger.name;<br>};<br>const jonas = { name: &#39;Jonas&#39;, passport: 12345 };<br>checkIn(&#39;LH123&#39;, jonas);<br>console.log(jonas.name); // Mr. Jonas</pre><p>3. <strong>Higher-Order Functions</strong></p><p>Functions can accept other functions as arguments or return new functions, enabling flexible operations like string transformations.</p><pre>const upperFirstWord = str =&gt; str.split(&#39; &#39;)[0].toUpperCase();<br>const transformer = (str, fn) =&gt; console.log(fn(str));<br>transformer(&#39;hello world&#39;, upperFirstWord); // HELLO</pre><p>4. <strong>The </strong><strong>call, </strong><strong>apply, and </strong><strong>bind Methods</strong></p><p>These methods enable flexible control over this context. For example:</p><pre>const lufthansa = { airline: &#39;Lufthansa&#39;, bookings: [], <br>book(flightNum, name) { <br>  console.log(`${name} booked on ${this.airline}`); } <br>};<br>const swiss = { airline: &#39;Swiss Air Lines&#39;, bookings: [] };<br>const book = lufthansa.book;<br>book.call(swiss, 583, &#39;Mary Cooper&#39;); // Mary Cooper booked on Swiss Air Lines</pre><p>5. <strong>Partial Application</strong></p><p>Functions like bind closures can preset arguments, creating reusable utilities.</p><pre>const addTax = rate =&gt; value =&gt; value + value * rate;<br>const addVAT = addTax(0.23);<br>console.log(addVAT(100)); // 123</pre><p>JavaScript functions provide a powerful foundation for writing clean and efficient code. From default parameters to higher-order functions and advanced techniques like call, bind, and partial application, mastering these concepts can significantly improve your development workflow. Start experimenting with these techniques to unlock the full potential of JavaScript!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=07a33bf4cea0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Guide to JavaScript Arrays]]></title>
            <link>https://medium.com/@mdfarid7830/a-quick-guide-to-javascript-arrays-86e211fa33ed?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/86e211fa33ed</guid>
            <category><![CDATA[javascript-array-methods]]></category>
            <category><![CDATA[javascript-es6]]></category>
            <category><![CDATA[javascript-arrays]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[learn-javascript]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 02:01:02 GMT</pubDate>
            <atom:updated>2024-11-18T02:10:14.201Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript arrays are versatile data structures that store ordered collections of elements. They come with powerful methods to manipulate and process data efficiently. Here’s a summary of key methods:</p><ul><li><strong>Mutate Original Array:</strong> Use .push(), .pop(), .shift(), .unshift(), and .splice() to add, remove, or modify elements. .sort() and .reverse() can change the order.</li><li><strong>Create New Arrays:</strong> Methods like .map(), .filter(), and .slice() create new arrays without affecting the original.</li><li><strong>Search Elements:</strong> Find values using .indexOf() or .find(), and their positions with .findIndex().</li><li><strong>Check Conditions:</strong> Use .some() or .every() to test conditions, and .includes() to verify if a value exists.</li><li><strong>Transform Arrays:</strong> Flatten arrays with .flat(), join values into a string using .join(), and reduce arrays to a single value with .reduce().</li><li><strong>Loop Through:</strong> Apply functions to each element using .forEach().</li></ul><p>Mastering these methods can make working with arrays in JavaScript efficient and intuitive! 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dT6HmOp6icUBVY9jiNisLQ.png" /></figure><ol><li><strong>push()</strong></li></ol><p>Adds a value to the end of the array.</p><pre>const arr = [1, 2];<br>arr.push(3);<br>console.log(arr); // [1, 2, 3]</pre><p><strong>2. unshift()</strong></p><p>Adds a value to the beginning of the array.</p><pre>const arr = [2, 3];<br>arr.unshift(1);<br>console.log(arr); // [1, 2, 3]</pre><p>3. pop()</p><p>Removes the last value from the array.</p><pre>const arr = [1, 2, 3];<br>arr.pop();<br>console.log(arr); // [1, 2]</pre><p><strong>4. shift()</strong></p><p>Removes the first value from the array.</p><pre>const arr = [1, 2, 3];<br>arr.shift();<br>console.log(arr); // [2, 3]</pre><h3>5. splice()</h3><p>Adds or removes elements from a specific index.</p><pre>const arr = [1, 2, 4];<br>arr.splice(2, 0, 3);<br>console.log(arr); // [1, 2, 3, 4]</pre><h3>6. reverse()</h3><p>Reverses the order of the array.</p><pre>const arr = [1, 2, 3];<br>arr.reverse();<br>console.log(arr); // [3, 2, 1]</pre><h3>7. sort()</h3><p>Sort the array alphabetically or numerically.</p><pre>const arr = [3, 1, 2];<br>arr.sort();<br>console.log(arr); // [1, 2, 3]</pre><h3>8. fill()</h3><p>Fills all or part of the array with a static value.</p><pre>const arr = [1, 2, 3];<br>arr.fill(0);<br>console.log(arr); // [0, 0, 0]</pre><h3>9. map()</h3><p>Creates a new array by applying a function to each element.</p><pre>const arr = [1, 2, 3];<br>const squared = arr.map(n =&gt; n * n);<br>console.log(squared); // [1, 4, 9]</pre><h3>10. filter()</h3><p>Filters elements based on a condition.</p><pre>const arr = [1, 2, 3, 4];<br>const even = arr.filter(n =&gt; n % 2 === 0);<br>console.log(even); // [2, 4]</pre><h3>11. slice()</h3><p>Extracts a portion of the array into a new array.</p><pre>const arr = [1, 2, 3];<br>const sliced = arr.slice(0, 2);<br>console.log(sliced); // [1, 2]</pre><h3>12. concat()</h3><p>Merges arrays into a new array.</p><pre>const arr1 = [1, 2];<br>const arr2 = [3, 4];<br>const merged = arr1.concat(arr2);<br>console.log(merged); // [1, 2, 3, 4]</pre><h3>13. flat()</h3><p>Flattens nested arrays into a single array.</p><pre>const arr = [1, [2, 3], [4]];<br>console.log(arr.flat()); // [1, 2, 3, 4]</pre><h3>14. flatMap()</h3><p>Maps and flattens the array in one step.</p><pre>const arr = [1, 2];<br>const mapped = arr.flatMap(n =&gt; [n, n * 2]);<br>console.log(mapped); // [1, 2, 2, 4]</pre><h3>15. indexOf()</h3><p>Finds the index of the first occurrence of a value.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.indexOf(2)); // 1</pre><h3>16. findIndex()</h3><p>Finds the index of the first element that meets a condition.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.findIndex(n =&gt; n &gt; 1)); // 1</pre><h3>17. find()</h3><p>Finds the first element that meets a condition.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.find(n =&gt; n &gt; 1)); // 2</pre><h3>18. includes()</h3><p>Check if a value exists in the array.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.includes(2)); // true</pre><h3>19. some()</h3><p>Checks if any element meets a condition.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.some(n =&gt; n &gt; 2)); // true</pre><h3>20. every()</h3><p>Checks if all elements meet a condition.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.every(n =&gt; n &gt; 0)); // true</pre><h3>21. join()</h3><p>Joins elements into a string with a separator.</p><pre>const arr = [1, 2, 3];<br>console.log(arr.join(&#39;-&#39;)); // &quot;1-2-3&quot;</pre><h3>22. reduce()</h3><p>Reduces the array to a single value by applying a function.</p><pre>const arr = [1, 2, 3];<br>const sum = arr.reduce((total, n) =&gt; total + n, 0);<br>console.log(sum); // 6</pre><h3>23. forEach()</h3><p>Loops through each element without returning a new array.</p><pre>const arr = [1, 2, 3];<br>arr.forEach(n =&gt; console.log(n));<br>// Output: 1 2 3</pre><p>Conclusion:</p><p>JavaScript arrays are incredibly powerful, offering a wide range of methods to handle data effectively. Whether you’re adding, removing, transforming, or searching elements, these methods make your code cleaner and more efficient. By understanding and mastering these tools, you can tackle complex data manipulation tasks with ease, enhancing your productivity as a developer. Dive in, experiment, and let arrays simplify your coding journey! 🌟</p><p><strong>“Thanks for staying with me till the end! 🎉”</strong></p><p>“If you found this article helpful, please consider giving it a few claps (up to 50) to help it reach more readers. 🙏✨”</p><p><strong>You can reach me from the links below:</strong></p><p><a href="https://www.linkedin.com/in/farid-mia-b551a9149/">https://www.linkedin.com/in/farid-mia-b551a9149/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86e211fa33ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Optimize JavaScript with Memoization”]]></title>
            <link>https://medium.com/@mdfarid7830/optimize-javascript-with-memoization-6c64578b60a1?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c64578b60a1</guid>
            <category><![CDATA[coding-best-practices]]></category>
            <category><![CDATA[improve-javascript-speed]]></category>
            <category><![CDATA[optimize-javascript-code]]></category>
            <category><![CDATA[javascript-performance]]></category>
            <category><![CDATA[memoization-in-javascript]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 15:58:02 GMT</pubDate>
            <atom:updated>2024-10-25T15:58:02.935Z</atom:updated>
            <content:encoded><![CDATA[<p>Memoization is a powerful technique to optimize the performance of expensive or frequently called functions. In JavaScript, it can be implemented by creating a function wrapper that stores the results of function calls with specific inputs. Here’s a concise approach to implementing memoization using a simple memoize function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n63N7IsJAr0oFLmNW-wfzw.png" /></figure><pre>function memoize(func) {<br>    const cache = new Map(); <br>    return function (...args) {<br>        const key = JSON.stringify(args);        if (cache.has(key)) {<br>            return cache.get(key);<br>        }<br>        const result = func.apply(this, args);<br>        cache.set(key, result);<br>        return result;<br>    };<br>}<br><br><br>const expensiveFunction = memoize((num) =&gt; {<br>    console.log(&quot;Computing...&quot;);<br>    return num * 2;<br>});<br><br>console.log(expensiveFunction(2));<br>console.log(expensiveFunction(2));</pre><h4>Why Use Memoization?</h4><p>Memoization saves time by storing previously computed results, so when the same inputs are encountered, we can fetch the result from memory instead of recalculating it. It’s particularly useful in scenarios involving complex calculations or repeated function calls, as it reduces redundant work and can significantly speed up your application.</p><h4>How This Works:</h4><ol><li><strong>Cache Initialization</strong>: We use a Map to store our cache because it allows for efficient key-value lookups.</li><li><strong>Key Generation</strong>: Arguments are serialized to a JSON string to create a unique cache key.</li><li><strong>Cache Check</strong>: If the key exists, the cached result is returned; otherwise, the function executes, and its result is cached.</li></ol><h4>Performance Benefits</h4><p>Memoization improves performance for repetitive tasks by leveraging cached results. This pattern can be applied to recursive functions, data processing tasks, and any computation-heavy logic.</p><p><strong>“Thanks for staying with me till the end! 🎉”</strong></p><p>“If you found this article helpful, please consider giving it a few claps (up to 50) to help it reach more readers. 🙏✨”</p><p><strong>You can reach me from the links below:</strong></p><p><a href="https://www.linkedin.com/in/farid-mia-b551a9149/">https://www.linkedin.com/in/farid-mia-b551a9149/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c64578b60a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Guide to PHP Abstract Classes with Examples]]></title>
            <link>https://medium.com/@mdfarid7830/a-quick-guide-to-php-abstract-classes-with-examples-ca71c2498595?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca71c2498595</guid>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[polymorphism]]></category>
            <category><![CDATA[abstract-methods]]></category>
            <category><![CDATA[object-oriented-program]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Wed, 23 Oct 2024 03:00:15 GMT</pubDate>
            <atom:updated>2024-10-23T03:00:15.904Z</atom:updated>
            <content:encoded><![CDATA[<p>In PHP, an abstract class serves as a template for other courses. It cannot be instantiated directly but provides a structure its subclasses must follow. Abstract classes are great for enforcing consistency and sharing common code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cY3Op3fyuTSxZYcJ4Y3tDw.png" /></figure><h3>What is an Abstract Class?</h3><p>An abstract class contains abstract methods (without bodies) that must be implemented by subclasses. It can also include concrete methods (with full implementation). The goal is to provide a framework for other classes while ensuring specific methods are defined.</p><h3>Key Features:</h3><ul><li><strong>Can not be instantiated</strong> directly.</li><li><strong>Must be extended</strong> by child classes.</li><li><strong>Abstract methods</strong>: Require subclasses to provide implementation.</li><li><strong>Concrete methods</strong>: Can be shared across all subclasses.</li></ul><p>Example:</p><pre>&lt;?php<br>abstract class Animal {<br>    abstract public function eat();<br>    abstract public function makeSound();<br>}<br><br>class Dog extends Animal {<br>    public function eat() { echo &quot;Dog is eating.\n&quot;; }<br>    public function makeSound() { echo &quot;Dog says: Woof Woof!\n&quot;; }<br>}<br><br>class Cat extends Animal {<br>    public function eat() { echo &quot;Cat is eating.\n&quot;; }<br>    public function makeSound() { echo &quot;Cat says: Meow Meow!\n&quot;; }<br>}<br><br>class Bird extends Animal {<br>    public function eat() { echo &quot;Bird is eating.\n&quot;; }<br>    public function makeSound() { echo &quot;Bird says: Chirp Chirp!\n&quot;; }<br>}<br><br>// Instantiate objects and call methods<br>$dog = new Dog();<br>$dog-&gt;eat();<br>$dog-&gt;makeSound();<br><br>$cat = new Cat();<br>$cat-&gt;eat();<br>$cat-&gt;makeSound();<br><br>$bird = new Bird();<br>$bird-&gt;eat();<br>$bird-&gt;makeSound();</pre><h3>Why Use Abstract Classes?</h3><ol><li><strong>Reusability</strong>: Common methods can be defined once and reused.</li><li><strong>Consistency</strong>: Forces subclasses to implement specific methods.</li><li><strong>Extensibility</strong>: Easily add new classes with a predefined structure.</li></ol><h3>Conclusion:</h3><p>Abstract classes allow you to define a base structure while ensuring consistent behavior across subclasses. They are perfect for organizing related classes that share common methods but need custom implementations.</p><p><strong>“Thanks for staying with me till the end! 🎉”</strong></p><p>“If you found this article helpful, please consider giving it a few claps (up to 50) to help it reach more readers. 🙏✨”</p><p><strong>You can reach me from the links below:</strong></p><p><a href="https://www.linkedin.com/in/farid-mia-b551a9149/">https://www.linkedin.com/in/farid-mia-b551a9149/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca71c2498595" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Design Patterns in PHP:]]></title>
            <link>https://medium.com/@mdfarid7830/mastering-design-patterns-in-php-17c922463a60?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/17c922463a60</guid>
            <category><![CDATA[design-pattern-php]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[coding-best-practices]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Tue, 01 Oct 2024 17:15:32 GMT</pubDate>
            <atom:updated>2024-10-01T17:29:51.769Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Level Up Your PHP Skills with Design Patterns!</h3><p>Design patterns are like magic formulas that simplify coding challenges. They make your code look cleaner, run more smoothly, and help you tackle common software problems with finesse. Whether you’re a PHP wizard or just starting your journey, these patterns will become your go-to techniques.</p><p>Let’s break down some of the most widely used design patterns in PHP and when you might want to pull them out of your coding toolkit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-S5Q8kQlpYTRA3sVtQdSw.png" /></figure><ol><li><strong>Singleton Pattern:</strong> 🏰</li></ol><p><strong>When to use:</strong><br>The Singleton Pattern ensures that a class has only one instance and provides a global point of access to it. This is useful when you need a single instance of a class shared across your entire application, like a database connection.</p><p><strong>Real-Life Example:</strong></p><p>Imagine you want to ensure that only one database connection is created throughout your project.</p><pre>class Database {<br>    private static $instance = null;<br>    private $connection;<br><br>    // Private constructor to prevent multiple instances<br>    private function __construct() {<br>        $this-&gt;connection = new PDO(&#39;mysql:host=localhost;dbname=test&#39;, &#39;root&#39;, &#39;&#39;);<br>    }<br><br>    // Returns the single instance of the class<br>    public static function getInstance() {<br>        if (self::$instance === null) {<br>            self::$instance = new Database();<br>        }<br>        return self::$instance;<br>    }<br><br>    public function getConnection() {<br>        return $this-&gt;connection;<br>    }<br>}<br><br>// Usage<br>$db1 = Database::getInstance();<br>$db2 = Database::getInstance();<br><br>// Both $db1 and $db2 share the same instance</pre><p>How it works:</p><ol><li><strong>Private Constructor:</strong> Prevents creating new instances directly.</li><li><strong>Static getInstance():</strong> Checks if an instance already exists. If not, it creates one and returns it.</li><li><strong>Single Instance:</strong> Both $db1 and $db2 point to the same instance, ensuring only one connection is used throughout.</li></ol><p>This pattern is ideal for managing shared resources like a database connection.</p><p>2. <strong>Factory Pattern:</strong> ⚙️</p><p><strong>When to use:</strong><br>The Factory Pattern is used when you need to create objects from a set of subclasses but want to centralize the decision-making on which class to instantiate. It simplifies making objects and allows for better control and flexibility.</p><p><strong>Real-Life Example:</strong></p><p>Think of a car manufacturing plant where different types of cars (like Sedan, SUV) are produced. The factory decides which car to produce based on the input type.</p><pre>interface Car {<br>    public function getType();<br>}<br><br>class Sedan implements Car {<br>    public function getType() {<br>        return &quot;Sedan&quot;;<br>    }<br>}<br><br>class SUV implements Car {<br>    public function getType() {<br>        return &quot;SUV&quot;;<br>    }<br>}<br><br>class CarFactory {<br>    public static function createCar($type) {<br>        if ($type === &#39;sedan&#39;) {<br>            return new Sedan();<br>        } elseif ($type === &#39;suv&#39;) {<br>            return new SUV();<br>        }<br>        throw new Exception(&quot;Invalid car type&quot;);<br>    }<br>}<br><br>// Usage<br>$sedan = CarFactory::createCar(&#39;sedan&#39;);<br>echo $sedan-&gt;getType();  // Output: Sedan<br><br>$suv = CarFactory::createCar(&#39;suv&#39;);<br>echo $suv-&gt;getType();    // Output: SUV</pre><h4>How it works:</h4><ol><li><strong>Interface Car:</strong> Defines the blueprint for car types, with a method getType().</li><li><strong>Concrete Classes (Sedan &amp; SUV):</strong> Both classes implement the Car interface and return the type of car they represent.</li><li><strong>Factory Class:</strong> CarFactory has a static method createCar() that decides which car to create based on the type passed as an argument. It returns an instance of either Sedan or SUV.</li><li><strong>Usage:</strong> When you call CarFactory::createCar(&#39;sedan&#39;), it returns a Sedan object, while calling CarFactory::createCar(&#39;suv&#39;) returns an SUV object.</li></ol><p>3. <strong>Observer Pattern</strong>: 🔔</p><p><strong>When to use:</strong><br>The Observer Pattern is used when you need to notify multiple objects about changes in the state of another object. It is commonly used in event-driven systems.</p><p><strong>Real-Life Example:</strong><br>Consider a news portal where subscribers get notified whenever new articles are published.</p><p><strong>Code Example:</strong></p><pre>interface Observer {<br>    public function update($news);<br>}<br><br>class NewsPublisher {<br>    private $observers = [];<br>    private $latestNews;<br><br>    public function subscribe(Observer $observer) {<br>        $this-&gt;observers[] = $observer;<br>    }<br><br>    public function notify() {<br>        foreach ($this-&gt;observers as $observer) {<br>            $observer-&gt;update($this-&gt;latestNews);<br>        }<br>    }<br><br>    public function publishNews($news) {<br>        $this-&gt;latestNews = $news;<br>        $this-&gt;notify();<br>    }<br>}<br><br>class Subscriber implements Observer {<br>    private $name;<br><br>    public function __construct($name) {<br>        $this-&gt;name = $name;<br>    }<br><br>    public function update($news) {<br>        echo $this-&gt;name . &quot; received news: &quot; . $news . &quot;\n&quot;;<br>    }<br>}<br><br>// Usage<br>$publisher = new NewsPublisher();<br>$sub1 = new Subscriber(&#39;Alice&#39;);<br>$sub2 = new Subscriber(&#39;Bob&#39;);<br><br>$publisher-&gt;subscribe($sub1);<br>$publisher-&gt;subscribe($sub2);<br>$publisher-&gt;publishNews(&#39;New PHP Version Released!&#39;);</pre><p><strong>Summary:</strong><br>The NewsPublisher notifies its subscribers (Observer) when new content is published using the publishNews method. Subscribers implement the Observer interface and respond when they receive updates.</p><p>4. <strong>Strategy Pattern</strong>: 🧠</p><p><strong>When to use:</strong><br>The Strategy Pattern is useful when you need to choose between multiple algorithms or methods dynamically at runtime, making them interchangeable.</p><p><strong>Real-Life Example:</strong><br>A payment gateway where you can choose between different payment methods, such as credit card or PayPal.</p><p><strong>Code Example:</strong></p><pre>interface PaymentStrategy {<br>    public function pay($amount);<br>}<br><br>class CreditCardPayment implements PaymentStrategy {<br>    public function pay($amount) {<br>        echo &quot;Paid $amount using Credit Card.\n&quot;;<br>    }<br>}<br><br>class PayPalPayment implements PaymentStrategy {<br>    public function pay($amount) {<br>        echo &quot;Paid $amount using PayPal.\n&quot;;<br>    }<br>}<br><br>class PaymentContext {<br>    private $strategy;<br><br>    public function __construct(PaymentStrategy $strategy) {<br>        $this-&gt;strategy = $strategy;<br>    }<br><br>    public function executePayment($amount) {<br>        $this-&gt;strategy-&gt;pay($amount);<br>    }<br>}<br><br>// Usage<br>$payment = new PaymentContext(new CreditCardPayment());<br>$payment-&gt;executePayment(100);<br><br>$payment = new PaymentContext(new PayPalPayment());<br>$payment-&gt;executePayment(200);</pre><p><strong>Summary:</strong><br>In this example, the PaymentContext allows different payment methods (strategies) to be applied dynamically. By switching between CreditCardPayment or PayPalPayment, we can easily process payments using different strategies.</p><p>5. <strong>Decorator Pattern</strong>: 🎨</p><p>The <strong>Decorator Pattern</strong> allows you to attach additional responsibilities to an object dynamically. Instead of creating complex subclass hierarchies, the decorator pattern gives you a flexible way to extend functionality by wrapping objects.</p><h4>When to Use the Decorator Pattern:</h4><ul><li>You want to add behavior to individual objects at runtime, either statically or dynamically.</li><li>You need to compose objects with multiple optional features or responsibilities.</li></ul><h4>Coffee Example in PHP</h4><p>In this example, we’ll create a basic coffee and then dynamically add extras like milk, sugar, and whipped cream using decorators.</p><pre>// Base Coffee interface<br>interface Coffee {<br>    public function getCost();<br>    public function getDescription();<br>}<br><br>// Concrete class: Simple Coffee<br>class SimpleCoffee implements Coffee {<br>    public function getCost() {<br>        return 50;<br>    }<br>    public function getDescription() {<br>        return &quot;Simple coffee&quot;;<br>    }<br>}<br><br>// Base Decorator class<br>class CoffeeDecorator implements Coffee {<br>    protected $coffee;<br><br>    public function __construct(Coffee $coffee) {<br>        $this-&gt;coffee = $coffee;<br>    }<br><br>    public function getCost() {<br>        return $this-&gt;coffee-&gt;getCost();<br>    }<br><br>    public function getDescription() {<br>        return $this-&gt;coffee-&gt;getDescription();<br>    }<br>}<br><br>// Adding Milk<br>class MilkDecorator extends CoffeeDecorator {<br>    public function getCost() {<br>        return $this-&gt;coffee-&gt;getCost() + 20;<br>    }<br>    public function getDescription() {<br>        return $this-&gt;coffee-&gt;getDescription() . &#39;, milk&#39;;<br>    }<br>}<br><br>// Adding Sugar<br>class SugarDecorator extends CoffeeDecorator {<br>    public function getCost() {<br>        return $this-&gt;coffee-&gt;getCost() + 30;<br>    }<br>    public function getDescription() {<br>        return $this-&gt;coffee-&gt;getDescription() . &#39;, sugar&#39;;<br>    }<br>}<br><br>// Usage example<br>$coffee = new SimpleCoffee();<br>$coffeeWithMilk = new MilkDecorator($coffee);<br>$coffeeWithMilkAndSugar = new SugarDecorator($coffeeWithMilk);<br><br>echo $coffeeWithMilkAndSugar-&gt;getDescription(); // Simple coffee, milk, sugar<br>echo $coffeeWithMilkAndSugar-&gt;getCost(); // 100</pre><h4>Conclusion</h4><p>The <strong>Decorator Pattern</strong> offers a flexible way to extend functionality dynamically without altering existing code. By using decorators, you can add multiple features (like milk, and sugar) to a base object (like coffee) at runtime in a clean and scalable way.</p><p>6. <strong>Abstract Factory Pattern</strong>: 🏭✨</p><p>The <strong>Abstract Factory Pattern</strong> is a creational pattern that provides an interface for creating families of related or dependent objects without specifying their exact concrete classes. It’s useful when you want to create objects that belong together in a structured way.</p><h4>When to Use:</h4><ul><li>You want to ensure that a set of related objects are created together.</li><li>You have multiple families of related objects, but you want to abstract their creation process.</li></ul><pre>// Abstract Factory Interface<br>interface VehicleFactory {<br>    public function createSeat(): Seat;<br>    public function createTire(): Tire;<br>}<br><br>// Abstract Product Interfaces<br>interface Seat {<br>    public function material();<br>}<br><br>interface Tire {<br>    public function type();<br>}<br><br>// Concrete Factory for Car<br>class CarFactory implements VehicleFactory {<br>    public function createSeat(): Seat {<br>        return new CarSeat();<br>    }<br>    public function createTire(): Tire {<br>        return new CarTire();<br>    }<br>}<br><br>// Concrete Factory for Bike<br>class BikeFactory implements VehicleFactory {<br>    public function createSeat(): Seat {<br>        return new BikeSeat();<br>    }<br>    public function createTire(): Tire {<br>        return new BikeTire();<br>    }<br>}<br><br>// Concrete Products for Car<br>class CarSeat implements Seat {<br>    public function material() {<br>        return &quot;Leather seat for car&quot;;<br>    }<br>}<br><br>class CarTire implements Tire {<br>    public function type() {<br>        return &quot;Radial tire for car&quot;;<br>    }<br>}<br><br>// Concrete Products for Bike<br>class BikeSeat implements Seat {<br>    public function material() {<br>        return &quot;Foam seat for bike&quot;;<br>    }<br>}<br><br>class BikeTire implements Tire {<br>    public function type() {<br>        return &quot;Tubeless tire for bike&quot;;<br>    }<br>}<br><br>// Usage Example<br>function createVehicle(VehicleFactory $factory) {<br>    $seat = $factory-&gt;createSeat();<br>    $tire = $factory-&gt;createTire();<br>    <br>    echo $seat-&gt;material() . &quot;\n&quot;;<br>    echo $tire-&gt;type() . &quot;\n&quot;;<br>}<br><br>// Choose Car or Bike Factory<br>$vehicleType = &#39;car&#39;; // Assume this is dynamic<br>if ($vehicleType === &#39;car&#39;) {<br>    $factory = new CarFactory();<br>} else {<br>    $factory = new BikeFactory();<br>}<br><br>createVehicle($factory);<br><br>// output<br>// Leather seat for car<br>// Radial tire for car</pre><h4>Why Use the Abstract Factory Pattern?</h4><ul><li><strong>Consistency</strong>: Ensures that all parts of a vehicle are created from the same family (Car or Bike).</li><li><strong>Extensibility</strong>: Adding a new vehicle type (e.g., Truck) is easy. Just create a new factory and its related parts.</li><li><strong>Separation of Concerns</strong>: The creation logic is decoupled from the client code.</li></ul><p><strong>7. Builder Pattern</strong>: 🏗️🛠️</p><p>The <strong>Builder Pattern</strong> is a creational design pattern that separates the construction of a complex object from its representation. This allows for the same construction process to create different representations of an object.</p><p><strong>When to Use:</strong></p><ul><li>When you have a complex object with multiple optional components and want to simplify its creation.</li><li>When the construction process should be independent of the final object’s structure.</li></ul><pre>// Product class: House<br>class House {<br>    private $parts = [];<br><br>    public function addPart($part) {<br>        $this-&gt;parts[] = $part;<br>    }<br><br>    public function listParts() {<br>        return implode(&#39;, &#39;, $this-&gt;parts);<br>    }<br>}<br><br>// Director class: Construction manager<br>class ConstructionManager {<br>    public function constructHouse(HouseBuilderInterface $builder) {<br>        $builder-&gt;buildWalls();<br>        $builder-&gt;buildDoors();<br>        $builder-&gt;buildRoof();<br>    }<br>}<br><br>// Builder interface<br>interface HouseBuilderInterface {<br>    public function buildWalls();<br>    public function buildDoors();<br>    public function buildRoof();<br>}<br><br>// Concrete builder class<br>class ConcreteHouseBuilder implements HouseBuilderInterface {<br>    private $house;<br><br>    public function __construct() {<br>        $this-&gt;house = new House();<br>    }<br><br>    public function buildWalls() {<br>        $this-&gt;house-&gt;addPart(&#39;Concrete Walls&#39;);<br>    }<br><br>    public function buildDoors() {<br>        $this-&gt;house-&gt;addPart(&#39;Wooden Doors&#39;);<br>    }<br><br>    public function buildRoof() {<br>        $this-&gt;house-&gt;addPart(&#39;Tile Roof&#39;);<br>    }<br><br>    public function getHouse() {<br>        return $this-&gt;house;<br>    }<br>}<br><br>// Usage Example<br>$manager = new ConstructionManager();<br>$builder = new ConcreteHouseBuilder();<br><br>$manager-&gt;constructHouse($builder);<br>$house = $builder-&gt;getHouse();<br>echo $house-&gt;listParts(); // Outputs: Concrete Walls, Wooden Doors, Tile Roof</pre><p><strong>Explanation:</strong></p><ul><li><strong>House</strong>: The product being built, which can have different components.</li><li><strong>Construction Manager</strong>: The director who manages the construction process, guiding the builder on what parts to build.</li><li><strong>HouseBuilderInterface</strong>: The interface that defines the methods for building the various parts of the house.</li><li><strong>ConcreteHouseBuilder</strong>: The concrete implementation of the builder that constructs a specific type of house.</li></ul><p>8. <strong>Prototype Pattern</strong>: 🧬✨</p><p>The <strong>Prototype Pattern</strong> is a creational design pattern that allows you to create new objects by copying an existing object, known as the prototype. This is particularly useful when creating a new instance from scratch is expensive or cumbersome.</p><p><strong>When to Use:</strong></p><ul><li>When you want to create new objects that share the same initial state as an existing object.</li><li>When the process of creating a new instance is more costly than copying an existing one.</li></ul><pre>// Prototype class: Document<br>class Document {<br>    private $content;<br><br>    public function __construct($content) {<br>        $this-&gt;content = $content;<br>    }<br><br>    public function clone() {<br>        return new Document($this-&gt;content);<br>    }<br><br>    public function getContent() {<br>        return $this-&gt;content;<br>    }<br><br>    public function setContent($content) {<br>        $this-&gt;content = $content;<br>    }<br>}<br><br>// Usage Example<br>$template = new Document(&#39;This is the original document content.&#39;);<br>$clone = $template-&gt;clone();<br><br>// Modifying the cloned document<br>$clone-&gt;setContent(&#39;This is the cloned document content.&#39;);<br><br>echo $template-&gt;getContent(); // Outputs: This is the original document content.<br>echo &quot;\n&quot;;<br>echo $clone-&gt;getContent();    // Outputs: This is the cloned document content.</pre><p><strong>Explanation:</strong></p><ul><li><strong>Document</strong>: The prototype class that represents the object you want to clone. It contains a clone() method to create a copy of itself.</li><li><strong>$template</strong>: The original document instance that serves as the prototype.</li><li><strong>$clone</strong>: The new document created by cloning the original, which can then be modified independently.</li></ul><p>9. <strong>Facade Pattern</strong>: 🏛️🔑</p><p>Problem:</p><p>In an online shopping system, there are multiple components involved when a user wants to place an order: managing the shopping cart, processing payment, and notifying the user. Without a facade, the user would need to interact with each component separately, making the process cumbersome.</p><pre>// Subsystem classes<br>class ShoppingCart {<br>    public function addItem($item) {<br>        echo &quot;Item &#39;$item&#39; added to the shopping cart.\n&quot;;<br>    }<br><br>    public function getTotal() {<br>        return 100; // Example total<br>    }<br>}<br><br>class PaymentProcessor {<br>    public function processPayment($amount) {<br>        echo &quot;Processing payment of $$amount.\n&quot;;<br>    }<br>}<br><br>class OrderNotifier {<br>    public function sendOrderConfirmation() {<br>        echo &quot;Order confirmation email sent.\n&quot;;<br>    }<br>}<br><br>// Facade class<br>class OnlineShoppingFacade {<br>    private $cart;<br>    private $paymentProcessor;<br>    private $notifier;<br><br>    public function __construct() {<br>        $this-&gt;cart = new ShoppingCart();<br>        $this-&gt;paymentProcessor = new PaymentProcessor();<br>        $this-&gt;notifier = new OrderNotifier();<br>    }<br><br>    public function placeOrder($item) {<br>        $this-&gt;cart-&gt;addItem($item);<br>        $total = $this-&gt;cart-&gt;getTotal();<br>        $this-&gt;paymentProcessor-&gt;processPayment($total);<br>        $this-&gt;notifier-&gt;sendOrderConfirmation();<br>    }<br>}<br><br>// Usage example<br>$shoppingFacade = new OnlineShoppingFacade();<br>$shoppingFacade-&gt;placeOrder(&quot;Laptop&quot;);<br><br>// output:<br>// Item &#39;Laptop&#39; added to the shopping cart.<br>// Processing payment of $100.<br>// Order confirmation email sent.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17c922463a60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of Rest Parameters, Map, Filter, and Reduce!”]]></title>
            <link>https://medium.com/@mdfarid7830/unlocking-the-power-of-rest-parameters-map-filter-and-reduce-b4a3a1afff98?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4a3a1afff98</guid>
            <category><![CDATA[js-array-iteration]]></category>
            <category><![CDATA[js-function]]></category>
            <category><![CDATA[js-array-method]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Wed, 25 Sep 2024 17:19:59 GMT</pubDate>
            <atom:updated>2024-09-25T17:19:59.118Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Unlocking the Power of Rest Parameters, Map, Filter, and Reduce!”</em></strong></p><p>Looking to simplify your JavaScript code and handle data more effectively? This post dives deep into how the rest parameter, along with map(), filter(), and reduce(), can make your functions more powerful and flexible. Whether you&#39;re new to this array of methods or looking to sharpen your skills, this guide will help you understand how to use them efficiently in real-life scenarios. Let’s explore how these tools can streamline your code and make it more expressive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GAGdzhBjslZmdM6LEVBaOQ.png" /></figure><ol><li><strong>Rest parameter:</strong></li></ol><p><strong>S</strong>cenario: Function arguments can vary in number, making it difficult to handle them consistently.</p><p><strong>Strategy:</strong> Use the rest parameter to gather all arguments into an array. This allows you to easily manage any number of inputs without ”needing to specify” them beforehand. The rest parameter enhances flexibility by letting functions accept multiple arguments in a more structured way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*_N_9aZFhpI0CtK94Nd90hw.png" /></figure><p>In this example, …numbers collects all the arguments passed to sumAll into an array, making it simple to perform operations like summing them. The rest parameter makes your functions more adaptable and cleaner to work with.</p><p>2. <strong>Array:- map(), filter() &amp; reduce():</strong></p><p><strong>S</strong>cenario: Iterating over arrays to transform, filter, or accumulate values can become repetitive and tedious.</p><p><strong>Strategy</strong>: Use map(), filter(), and reduce() for common array operations.</p><p>map(): To transform each element in an array.</p><p>filter(): To select elements that meet certain criteria.</p><p>reduce(): To accumulate or combine all array values into a single result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*ovw4subeEuDF3rn-SK_vRg.png" /></figure><p>These array methods offer a functional way to manipulate arrays by transforming, filtering, or reducing them, helping to make your code clearer and more compact.</p><p><strong>Conclusion:</strong></p><p>In JavaScript, rest parameters, map, filter, and reduce enhance data manipulation. The <strong>rest parameter</strong> (...) allows variable arguments as an array. The <strong>map</strong> method transforms elements while <strong>filter</strong> selecting elements based on conditions. <strong>reduce</strong> aggregates values into a single output, enabling cleaner, maintainable code.</p><p><strong>“Thanks for staying with me till the end! 🎉”</strong></p><p>“If you found this article helpful, please consider giving it a few claps (up to 50) to help it reach more readers. 🙏✨”</p><p><strong>You can reach me from the links below:</strong></p><p><a href="https://www.linkedin.com/in/farid-mia-b551a9149/">https://www.linkedin.com/in/farid-mia-b551a9149/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4a3a1afff98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“5 Essential PHP Array Functions Every Developer Should Master”]]></title>
            <link>https://medium.com/@mdfarid7830/5-essential-php-functions-every-developer-should-master-1afd931cdc9f?source=rss-64ecb126d05f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1afd931cdc9f</guid>
            <dc:creator><![CDATA[Farid Mia]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 17:19:28 GMT</pubDate>
            <atom:updated>2024-09-24T18:38:03.520Z</atom:updated>
            <content:encoded><![CDATA[<p>“5 Essential PHP Array Functions Every Developer Should Master”</p><p><strong>Are you ready to explore some crucial PHP functions?</strong></p><p>Are you looking to enhance your skills as a developer? Of course, you are!</p><p>If that’s your goal, you’ve come to the right place. Let’s dive into the functions that will help you level up without further delay.</p><ol><li>array_merge():</li></ol><p>Suppose you’re building an e-commerce website that has separate product categories for electronics and furniture, but you want to create a single list to display all available products on the homepage. Using array_merge(), you can easily combine the two arrays into one unified list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*UmNwCeJacBqvwRE1c_n2iQ.png" /></figure><p>In this article, we used array_merge() to combine product lists from different categories, demonstrating how easily PHP handles array merging. Whether you’re working with product catalogs, user data, or any other arrays, array_merge() simplifies combining data and saves you time in writing code.</p><p>2. array_filter():</p><p>array_filter() allows you to iterate over an array and return a new array consisting of only the elements that meet the condition defined in a callback function. This is particularly useful when you want to filter out unwanted data or focus on specific elements within large datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*0sWn2aA8d7QWzjhQ-mHAVw.png" /></figure><p>array_filter() is a powerful PHP function that filters arrays based on defined conditions using a callback function. It allows you to easily include or exclude elements that meet specific criteria, such as removing products priced above $400 in an e-commerce context. Beyond e-commerce, it&#39;s useful for processing large datasets and refining array data across various applications. Using array_filter() helps maintain clean, efficient, and manageable PHP code.</p><p>3. array_map():</p><p>array_map() provides an efficient and readable way to transform arrays without the need for manual loops. Instead of writing repetitive code, you can leverage array_map() to apply consistent transformations to all elements of an</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*WU-oE_xu613hFrH6BPswmw.png" /></figure><p>In this article, we used array_map() to format product prices for an e-commerce platform, demonstrating how it simplifies array transformations in PHP. Whether you’re modifying arrays, normalizing data, or performing other transformations, array_map() is a powerful tool that enhances both the readability and efficiency of your code.</p><p>4. array reduce():</p><p>In PHP, working with arrays is a common practice, especially when dealing with datasets like product lists or user data. Often, we need to process these arrays and consolidate the data into a single value. This is where PHP’s array_reduce() function comes into play, providing an efficient and elegant solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*JOpR0jGThM6jhoNFfKO-ww.png" /></figure><p>In this article, we’ll demonstrate how to use array_reduce() to calculate the total price of items in a shopping cart. This is a practical example of reducing an array of products into a single output — the total cost.</p><p>5. json_encode() &amp; json_decode():</p><p>In PHP, json_encode() and json_decode() are indispensable when working with APIs, storing data, or interacting with external systems that require JSON. Whether you&#39;re sending product data to the frontend or processing JSON responses from external sources, these functions make data conversion seamless and efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*ktqLpS8Q9UATRAtDgouIsA.png" /></figure><h3>Conclusion</h3><p>PHP offers a variety of built-in functions that simplify complex tasks and enhance the efficiency of your code, especially in large-scale applications. Leveraging functions like array_reduce(), array_map(), array_filter(), array_merge(), and json_encode() / json_decode() enables you to write more concise, readable, and optimized code. By incorporating these powerful tools, you can streamline development and ensure that your projects are both professional and performant.</p><p><strong>“Thanks for staying with me till the end! 🎉”</strong></p><p>“If you found this article helpful, please consider giving it a few claps (up to 50) to help it reach more readers. 🙏✨”</p><p><strong>You can reach me from the links below:</strong></p><p><a href="https://www.linkedin.com/in/farid-mia-b551a9149/">https://www.linkedin.com/in/farid-mia-b551a9149/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1afd931cdc9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>