From ef981c09abf2053fd747984c8a04d87143b233ec Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 25 Sep 2026 10:43:41 +0200 Subject: [PATCH] chore: sync content to repo (#10378) Co-authored-by: nilbuild <4921183+nilbuild@users.noreply.github.com> --- .../php/content/_get@GFYGFVfxkOoPI5mI4zSt1.md | 12 +------ .../content/_post@qNG-a4iIO-puZsMwAMzYC.md | 11 +----- .../content/_request@A6rfW4uJhyfAX2b18_EEC.md | 7 +--- .../content/_server@7Ja2at_N9tRTlvSGahrqn.md | 6 +--- ...onymous-functions@Nr5m6wQLp7VyG3AucrSc8.md | 15 ++------ ...ssociative-arrays@i_NRsOJNNp7AOqMgu5Jg8.md | 13 ++----- .../autoloading@qFiTsf6Es-gwqe6J6bdL1.md | 13 ++----- ...asting-data-types@pzReF4C0mcCWAnpfIJbwl.md | 9 +---- .../content/composer@yVFDu2aTiEZ4PWMdKdW2P.md | 9 ++--- ...figuration-tuning@VpwwF8j5ZtXVSbzNfE7Sx.md | 10 ++---- ...onnection-pooling@txUyPR_tdC8iTJV3RtvBz.md | 4 +-- .../constants@VLRLymQmLfscrBfzXKvHi.md | 7 ++-- ...uctor--destructor@oNUt1oT8pYBVvH0S2P6cb.md | 23 ++----------- .../content/cookies@so03-fK7E2WvTm6XsPq4i.md | 2 +- .../csrf-protection@J9yIXZTtwbFzH2u4dI1ep.md | 16 ++------- .../csv-processing@MRDjEjbkMpk7shcWAoPOF.md | 12 +------ .../php/content/curl@KC6D81-T-FwQc7Osw1rlY.md | 17 ++-------- .../data-types@srIHPZabaCGdB5VvUXaMa.md | 7 +--- ...tabase-migrations@meplwvmHMtI3Sb_fyodzZ.md | 8 ++--- ...--optional-params@RgVP99rJJ8FVecIA45w20.md | 11 ++---- ...endency-injection@KEE50C6lOS4eX8sAbfhYe.md | 26 ++------------ .../php/content/echo@2ykzBBdYhWuM-neGf0AWP.md | 9 +---- ...ronment-variables@fitjnLYKLHJ2P5G7JAvzm.md | 14 ++------ ...g-system-commands@VhyYNGhOdKKrz_-uTkrjD.md | 12 ++----- .../file-permissions@tgIyG6vHWpe9sz6lHmj5a.md | 2 +- .../file-uploads@HNo8QO4aPbvgePiA4l6tq.md | 4 +-- .../form-processing@sYI7f1PYP7G30_Uj2mZRv.md | 4 +-- ...ction-declaration@1nODJchgSuWbcvSlxnWeE.md | 11 ++---- .../functions@WiGv7vi7Mtw-YqPMcnnyw.md | 13 ++----- .../http-methods@tn_iIfaJZVtPK6vFds7FH.md | 2 +- .../content/ifelse@-McOv-ZPTGayX7Mx2Thw1.md | 14 ++------ .../content/include@hKfv7V6bl2LXssq9Ffi7C.md | 11 ++---- .../include_once@SwtLDgyPmDry20qS4FBfH.md | 11 ++---- .../indexed-arrays@j2S8dP3HlAOOoZdpj-7Dx.md | 9 ++--- .../inheritance@c5q2e_jyMt8Pir5Od3lRi.md | 24 ++----------- .../input-validation@93oEIZttb85S23C1fLraP.md | 13 ++----- .../interfaces@vu0H-TsD7hkJgOQbSRj92.md | 26 ++------------ ...troduction-to-php@_hYN0gEi9BL24nptEtXWU.md | 11 +----- .../json-processing@DB2cxZE58WCCavW2PNwmf.md | 17 +--------- .../php/content/lamp@7LjxtrmgJtTJc0_kP83Tr.md | 2 +- .../content/loops@qwt8xN4vuTrY-D0czYITI.md | 13 ++----- .../magic-methods@rSXsPWto7Jeyw3Szl9pvf.md | 15 ++------ .../php/content/mamp@t7p7TU2khaxsZPYAdwFAA.md | 2 +- .../content/match@3gNzX-bw2iqur7U7-_W38.md | 13 ++----- ...memory-management@bt7dK2PcOZ72B9HXPyMwL.md | 16 ++------- ...imensional-arrays@uARTOZ-ZwugSmbCJoRS5Y.md | 12 ++----- .../content/mysqli@YLuo0oZJzTCoiZoOSG57z.md | 22 ++---------- .../named-arguments@RkNjYva8o_jXp9suz5YdG.md | 10 ++---- .../namespaces@9raJ06lKRZITbjWeLil-F.md | 11 ++---- .../content/nginx@aspZpACHEKOsi_Er5FYPY.md | 9 ++--- ...ional-mapping-orm@SeqGIfcLuveZ2z5ZSXcOd.md | 9 ++--- .../oop-fundamentals@yTviiPFR5b_dr3WyxdxxQ.md | 17 ++-------- .../opcode-caching@NieqZd1juaNYoZOrB7e31.md | 11 ++---- ...rs--return-values@mpQKoBzsOa-5iWo08sOhQ.md | 14 ++------ .../password-hashing@JbWFfJiCRrXDhnuIx_lqx.md | 14 ++------ .../php/content/pdo@cJtPz1RMN1qDE4eRdv4N_.md | 16 ++------- ...ance-optimization@M1nVsh_sCSFJRf6-7Ttsj.md | 20 ++--------- .../php/content/pest@d6MydchA52HIxfAUjmZui.md | 9 ++--- .../php-cs-fixer@r07k_hT2z2EiIBH4q3F7-.md | 11 ++---- .../content/php-fpm@AoGS-5MSkp8gtJFQVPSBE.md | 15 ++------ .../content/phpstan@12k71gNfwAcT9K5aLWgbZ.md | 12 ++----- .../content/phpunit@NfBKKwG2GGBPppOjoLLBg.md | 27 ++------------- .../polymorphism@gtq5KrghF28f5G8nuDcYQ.md | 34 ++----------------- .../process-control@NTKUMgsKGYISIyhgOJPQn.md | 18 ++-------- ...filing-techniques@_Dh78x_tPLqZweg--qZFQ.md | 8 ++--- ...rties-and-methods@MRAPXshy9RoYdReY6grf_.md | 18 ++-------- .../content/psalm@T1XD93j6Lkpl88JSmys9b.md | 8 ++--- .../psr-standards@3tONibbRgK7HCwGTE2Gqw.md | 17 ++-------- .../reading-files@S9wTlkbv9-R6dohhZ47hs.md | 16 ++------- .../recursion@D9ybK5INH5zSOcYMb5ZPi.md | 15 ++------ .../content/require@Kaaqu-mN7xvHN6CbIn616.md | 4 +-- .../require_once@-CyJbsg2ho3RvfzKnJj5C.md | 13 ++----- ...zation-techniques@tfC1tCrbvH5J43WUpG9Yb.md | 8 ++--- .../content/sessions@qobzzgzArNHLLn9Oiqc6G.md | 2 +- .../sql-injection@801vB_JMas4ucriUmfrLg.md | 4 +-- .../state-management@CGehmZjcgTWC7fQAvxmNW.md | 2 +- .../static-analysis@PrG_5dyBblXsWYYRcOJMa.md | 10 ++---- ...ds-and-properties@qlkpwXfOc1p7j37hrzffI.md | 17 ++-------- .../content/switch@bgJ9-m6Fiu3VCc-NZlbpn.md | 22 ++---------- .../content/symfony@57VSMVePOr9qUD5x_LNdf.md | 9 ++--- .../content/traits@GR09ns9B-0cONQaQ_uj-7.md | 20 ++--------- ...type-declarations@sPW-Ti2VyNYzxq6EYkbn7.md | 15 ++------ .../content/var_dump@JCCeVC0hOrvIeyfg1ScKA.md | 10 ++---- ...riables-and-scope@D0BtyxyjIBcpfn5wP23WC.md | 9 +---- ...ariadic-functions@rtmytETfyyLdcXUC0QyzL.md | 14 ++------ .../writing-files@two4UycJaCfSp6jQqtTAb.md | 12 ++----- .../content/xampp@-wniKEBwbF0Fi1fHpF-Gc.md | 2 +- .../content/xdebug@lFoHoMRywCWa056ii5cKQ.md | 16 ++------- .../xml-processing@ggkWo0DRSSDDkHpbiyUyf.md | 7 +--- .../xss-prevention@DxqQrToZSayWplKdCkTgT.md | 11 ++---- .../php/content/yii@zsscRQZIq5o0JZir9hlz-.md | 8 +++++ .../zend-debugger@KpQb5Zh3GUcbYUyXHvyu2.md | 4 +-- 92 files changed, 171 insertions(+), 927 deletions(-) create mode 100644 roadmaps/php/content/yii@zsscRQZIq5o0JZir9hlz-.md diff --git a/roadmaps/php/content/_get@GFYGFVfxkOoPI5mI4zSt1.md b/roadmaps/php/content/_get@GFYGFVfxkOoPI5mI4zSt1.md index b3bbcdea7..6c7129c3c 100644 --- a/roadmaps/php/content/_get@GFYGFVfxkOoPI5mI4zSt1.md +++ b/roadmaps/php/content/_get@GFYGFVfxkOoPI5mI4zSt1.md @@ -1,16 +1,6 @@ # $_GET -$\_GET is a pre-defined array in PHP, that's used to collect form-data sent through HTTP GET method. It's useful whenever you need to process or interact with data that has been passed in via a URL's query string. For an example if you have a form with a GET method, you can get the values of the form elements through this global $\_GET array. Here’s an example: - -
- - -Using $\_GET in `test.php`, you can fetch the 'fname' value from the URL: - - echo "Name is: " . $_GET['fname']; +`$_GET` contains variables passed to the script via URL query parameters. For a URL like `page.php?id=5&lang=en`, `$_GET['id']` returns `5`. Query string data should always be validated and sanitized before use, as it is user-supplied input. Visit the following resources to learn more: diff --git a/roadmaps/php/content/_post@qNG-a4iIO-puZsMwAMzYC.md b/roadmaps/php/content/_post@qNG-a4iIO-puZsMwAMzYC.md index e920a7e77..821deb30d 100644 --- a/roadmaps/php/content/_post@qNG-a4iIO-puZsMwAMzYC.md +++ b/roadmaps/php/content/_post@qNG-a4iIO-puZsMwAMzYC.md @@ -1,15 +1,6 @@ # $_POST -`$_POST` is a superglobal variable in PHP that's used to collect form data submitted via HTTP POST method. Your PHP script can access this data through `$_POST`. Let's say you have a simple HTML form on your webpage. When the user submits this form, the entered data can be fetched using `$_POST`. Here's a brief example: - - - - -In this code, `$_POST["name"]` fetches the value entered in the 'name' field of the form. Always be cautious when using `$_POST` as it may contain user input which is a common source of vulnerabilities. Always validate and sanitize data from `$_POST` before using it. +`$_POST` holds variables submitted through an HTTP POST request, typically from HTML forms with `method="post"`. Unlike GET data, POST data is not visible in the URL. It is used for form submissions, login requests, and any operation that sends data to the server. POST data must be sanitized before use. Visit the following resources to learn more: diff --git a/roadmaps/php/content/_request@A6rfW4uJhyfAX2b18_EEC.md b/roadmaps/php/content/_request@A6rfW4uJhyfAX2b18_EEC.md index ea4c64c4d..0ae0bae9f 100644 --- a/roadmaps/php/content/_request@A6rfW4uJhyfAX2b18_EEC.md +++ b/roadmaps/php/content/_request@A6rfW4uJhyfAX2b18_EEC.md @@ -1,11 +1,6 @@ # $_REQUEST -$\_REQUEST is a PHP superglobal variable that contains the contents of both $\_GET, $\_POST, and $\_COOKIE. It is used to collect data sent via both the GET and POST methods, as well as cookies. $\_REQUEST is useful if you do not care about the method used to send data, but its usage is generally discouraged as it could lead to security vulnerabilities. Here's a simple example: - - $name = $_REQUEST['name']; - - -This statement will store the value of the 'name' field sent through either a GET or POST method. Always remember to sanitize user input to avoid security problems. +`$_REQUEST` merges the contents of `$_GET`, `$_POST`, and `$_COOKIE` into a single superglobal array. Because it combines multiple sources, it is less predictable and generally avoided in favor of using `$_GET` or `$_POST` directly. The order of precedence among sources is controlled by `php.ini`. Visit the following resources to learn more: diff --git a/roadmaps/php/content/_server@7Ja2at_N9tRTlvSGahrqn.md b/roadmaps/php/content/_server@7Ja2at_N9tRTlvSGahrqn.md index c54296420..1f7ca7dcf 100644 --- a/roadmaps/php/content/_server@7Ja2at_N9tRTlvSGahrqn.md +++ b/roadmaps/php/content/_server@7Ja2at_N9tRTlvSGahrqn.md @@ -1,10 +1,6 @@ # $_SERVER -The `$_SERVER` is a superglobal in PHP, holding information about headers, paths, and script locations. $\_SERVER is an associative array containing server variables created by the web server. This can include specific environmental configurations, the server signature, your PHP script's paths and details, client data, and the active request/response sequence. Among its many uses, `$_SERVER['REMOTE_ADDR']` can help get the visitor's IP while `$_SERVER['HTTP_USER_AGENT']` offers information about their browser. Don't forget to sanitize the content before use to prevent security exploits. - -Here's an easy code sample that prints the client's IP: - - echo 'Your IP is: ' . $_SERVER['REMOTE_ADDR']; +`$_SERVER` is a superglobal array containing information about the server environment and the current HTTP request. Common entries include `$_SERVER['REQUEST_METHOD']`, `$_SERVER['HTTP_HOST']`, `$_SERVER['SCRIPT_NAME']`, and `$_SERVER['REMOTE_ADDR']`. Its contents vary depending on the server and request context. Visit the following resources to learn more: diff --git a/roadmaps/php/content/anonymous-functions@Nr5m6wQLp7VyG3AucrSc8.md b/roadmaps/php/content/anonymous-functions@Nr5m6wQLp7VyG3AucrSc8.md index e0bd85e5e..e55cb114a 100644 --- a/roadmaps/php/content/anonymous-functions@Nr5m6wQLp7VyG3AucrSc8.md +++ b/roadmaps/php/content/anonymous-functions@Nr5m6wQLp7VyG3AucrSc8.md @@ -1,17 +1,6 @@ # Anonymous Functions - -Anonymous functions in PHP, also known as closures, are functions that do not have a specified name. They are most frequently used as a value for callback parameters, but can be used in many other ways. When creating an anonymous function, you can also inherit variables from the parent scope. Here's a basic usage example: - - $greet = function($name) - { - printf("Hello %s\r\n", $name); - }; - - $greet('World'); - $greet('PHP'); - - -In this example, we're creating an anonymous function and assigning it to the variable `$greet`. We then call this anonymous function using $greet with 'World' and 'PHP' as arguments. + +Anonymous functions (closures) are functions without a name, typically assigned to a variable or passed as a callback. They are created with the `function` keyword and can capture variables from the surrounding scope using the `use` keyword. Arrow functions (`fn`) provide a shorter syntax for simple expressions. Visit the following resources to learn more: diff --git a/roadmaps/php/content/associative-arrays@i_NRsOJNNp7AOqMgu5Jg8.md b/roadmaps/php/content/associative-arrays@i_NRsOJNNp7AOqMgu5Jg8.md index e96adba35..daaf576e0 100644 --- a/roadmaps/php/content/associative-arrays@i_NRsOJNNp7AOqMgu5Jg8.md +++ b/roadmaps/php/content/associative-arrays@i_NRsOJNNp7AOqMgu5Jg8.md @@ -1,15 +1,6 @@ # Associative Arrays - -Associative arrays in PHP are a type of array that uses named keys instead of numeric ones. This provides a more human-readable way to store data where each value can be accessed by its corresponding string key. An example of an associative array could be storing names as keys and their corresponding ages as values. Here's a brief example: - - $ages = [ - "Peter" => 35, - "John" => 42, - "Mary" => 27 - ]; - - -In this case, to find out John's age, you would simply use `echo $ages['John']` where 'John' is the key. Associative arrays are also easy to loop through using the `foreach` construct. + +Associative arrays use named string keys instead of numeric indexes. You define them with explicit key-value pairs: `['name' => 'Alice', 'age' => 30]`. Values are accessed by key, like `$user['name']`. They are commonly used to represent structured data like rows from a database. Visit the following resources to learn more: diff --git a/roadmaps/php/content/autoloading@qFiTsf6Es-gwqe6J6bdL1.md b/roadmaps/php/content/autoloading@qFiTsf6Es-gwqe6J6bdL1.md index fb5df14c7..3d6a765bb 100644 --- a/roadmaps/php/content/autoloading@qFiTsf6Es-gwqe6J6bdL1.md +++ b/roadmaps/php/content/autoloading@qFiTsf6Es-gwqe6J6bdL1.md @@ -1,15 +1,6 @@ # Autoloading - -Autoloading is a convenient feature in PHP that allows for automated loading of classes or files when they are needed. For example, if you have a class that is not yet included or required in the script, and you're instantiating that class, PHP would automatically include that class file for you, given that it complies with the standard PHP autoloading conventions. This feature cuts down the need to manually include or require files and makes your code cleaner and more efficient to manage. Here's a simple example: - - spl_autoload_register(function ($class_name) { - include $class_name . '.php'; - }); - - $obj = new MyClass(); - - -In this example, PHP will automatically load the MyClass.php file when the MyClass is instantiated. + +Autoloading automatically loads PHP class files when they are first used, without requiring manual `include` or `require` calls. PHP's `spl_autoload_register()` registers a custom autoloader function. Composer generates a PSR-4-compliant autoloader that maps namespaces to directory structures, which is the standard approach in modern PHP. Visit the following resources to learn more: diff --git a/roadmaps/php/content/casting-data-types@pzReF4C0mcCWAnpfIJbwl.md b/roadmaps/php/content/casting-data-types@pzReF4C0mcCWAnpfIJbwl.md index ce40262d1..0d5804206 100644 --- a/roadmaps/php/content/casting-data-types@pzReF4C0mcCWAnpfIJbwl.md +++ b/roadmaps/php/content/casting-data-types@pzReF4C0mcCWAnpfIJbwl.md @@ -1,13 +1,6 @@ # Casting Data Types -PHP, as a loose typing language, allows us to change the type of a variable or to transform an instance of one data type into another. This operation is known as Casting. When to use casting, however, depends on the situation - it is recommendable when you want explicit control over the data type for an operation. The syntax involves putting the intended type in parentheses before the variable. For example, if you wanted to convert a string to an integer, you'd use: `$myVar = "123"; $intVar = (int) $myVar;`. Here, `$intVar` would be an integer representation of `$myVar`. Remember, the original variable type remains unchanged. - -Here's an example of type casting in PHP: - - +Type casting in PHP converts a value from one type to another. You cast explicitly by placing the target type in parentheses before the value, like `(int)$value`. PHP also performs implicit type juggling in comparisons and arithmetic, which can lead to unexpected results if not accounted for. Visit the following resources to learn more: diff --git a/roadmaps/php/content/composer@yVFDu2aTiEZ4PWMdKdW2P.md b/roadmaps/php/content/composer@yVFDu2aTiEZ4PWMdKdW2P.md index 1b0950ce6..0e534d99f 100644 --- a/roadmaps/php/content/composer@yVFDu2aTiEZ4PWMdKdW2P.md +++ b/roadmaps/php/content/composer@yVFDu2aTiEZ4PWMdKdW2P.md @@ -1,11 +1,6 @@ # Composer - -Composer is a fundamental tool in modern PHP development. It simplifies the management of project dependencies, allowing you to declare what you need and automatically installing those resources in your project. For example, if your PHP project requires a certain library, Composer will fetch the appropriate version and make sure it's available for your project. Here's an example of how to add a dependency using Composer: - - composer require vendor/package - - -This command adds the `vendor/package` dependency to your project. The same goes for removing dependencies, updating them, and more. + +Composer is the standard dependency manager for PHP. It reads a `composer.json` file to resolve and download packages from Packagist, records exact installed versions in `composer.lock`, and generates the autoloader. Nearly all modern PHP projects use Composer to manage third-party libraries. Visit the following resources to learn more: diff --git a/roadmaps/php/content/configuration-tuning@VpwwF8j5ZtXVSbzNfE7Sx.md b/roadmaps/php/content/configuration-tuning@VpwwF8j5ZtXVSbzNfE7Sx.md index 416803694..e3e075e68 100644 --- a/roadmaps/php/content/configuration-tuning@VpwwF8j5ZtXVSbzNfE7Sx.md +++ b/roadmaps/php/content/configuration-tuning@VpwwF8j5ZtXVSbzNfE7Sx.md @@ -1,12 +1,6 @@ # Configuration Tuning - -For performance optimization in PHP, configuration tuning is a crucial step. You can manipulate several settings in your php.ini file to enhance your PHP application's performance. For instance, `memory_limit` is a key parameter that specifies the maximum amount of memory a script can consume. Optimizing this setting will prevent the PHP scripts from eating up all server resources. Similarly, adjusting the `max_execution_time` limits the time a script runs. Just ensure careful configuration since restrictive settings could lead to issues. Here's a simple example of how you might modify these parameters: - - // Updating memory_limit - ini_set('memory_limit','256M'); - - // Updating max_execution_time - ini_set('max_execution_time', '300'); + +PHP's behavior is controlled through `php.ini` settings covering memory limits, execution timeouts, error reporting, upload sizes, and more. Tuning these settings for production involves balancing resource usage with application needs. Runtime configuration can also be overridden per-file using `ini_set()` for non-security-sensitive settings. Visit the following resources to learn more: diff --git a/roadmaps/php/content/connection-pooling@txUyPR_tdC8iTJV3RtvBz.md b/roadmaps/php/content/connection-pooling@txUyPR_tdC8iTJV3RtvBz.md index 7b6b92080..9ae0e70ce 100644 --- a/roadmaps/php/content/connection-pooling@txUyPR_tdC8iTJV3RtvBz.md +++ b/roadmaps/php/content/connection-pooling@txUyPR_tdC8iTJV3RtvBz.md @@ -1,6 +1,6 @@ # Connection Pooling - -Connection pooling is a technique used in PHP to manage and maintain multiple open connections with a database. It reduces the time overhead of constantly opening and closing connections, and ensures efficient utilisation of resources. Connection pooling limits the number of connections opened with the database and instead reuses a pool of existing active connections, thereby significantly enhancing the performance of PHP applications. When a PHP script needs to communicate with the database, it borrows a connection from this pool, performs the operations, and then returns it back to the pool. Although PHP doesn't have native support for connection pooling, it can be achieved through third-party tools like 'pgBouncer' when using PostgreSQL or 'mysqlnd\_ms' plugin with MySQL. Note, it's recommended to use connection pooling when you've a high-traffic PHP application. + +Connection pooling reuses existing database connections instead of opening a new connection for each request. PHP itself is stateless per request, so persistent connections (`PDO::ATTR_PERSISTENT`) simulate pooling within a single process. External poolers like PgBouncer handle true connection pooling for high-traffic applications using PostgreSQL. Visit the following resources to learn more: diff --git a/roadmaps/php/content/constants@VLRLymQmLfscrBfzXKvHi.md b/roadmaps/php/content/constants@VLRLymQmLfscrBfzXKvHi.md index 4e0ed44bf..dd7a525da 100644 --- a/roadmaps/php/content/constants@VLRLymQmLfscrBfzXKvHi.md +++ b/roadmaps/php/content/constants@VLRLymQmLfscrBfzXKvHi.md @@ -1,9 +1,6 @@ # Constants - -Constants in PHP are fixed values that do not change during the execution of the script. They can be handy for values that need to be reused often like a website's URL, a company's name, or even a hardcoded database connection string. Unlike variables, once a constant is defined, it cannot be undefined or reassigned. Constants are case-sensitive by default but this can be overridden. They are defined using the define() function or the const keyword. For instance, you can create a constant to hold the value of Pi and call it in your script like this: - - define("PI", 3.14); - echo PI; // Outputs: 3.14 + +Constants are identifiers for fixed values that cannot be changed during script execution. They are defined using `define()` or the `const` keyword. Unlike variables, constants do not use a `$` prefix and are globally accessible throughout the script without needing the `global` keyword. Visit the following resources to learn more: diff --git a/roadmaps/php/content/constructor--destructor@oNUt1oT8pYBVvH0S2P6cb.md b/roadmaps/php/content/constructor--destructor@oNUt1oT8pYBVvH0S2P6cb.md index 8064491b7..d28a43b70 100644 --- a/roadmaps/php/content/constructor--destructor@oNUt1oT8pYBVvH0S2P6cb.md +++ b/roadmaps/php/content/constructor--destructor@oNUt1oT8pYBVvH0S2P6cb.md @@ -1,25 +1,6 @@ # Constructor / Destructor - -Constructor and Destructor methods are fundamental components of Object-Oriented Programming (OOP) in PHP. A constructor is a special type of method that automatically runs upon creating an object, often used to set property values or default behaviors. On the other hand, a destructor is a method that is automatically invoked when an object is due to be destroyed, perfect for cleanup activities. Here is a basic example: - - class TestClass { - public $value; - - // Constructor Method - public function __construct($val) { - $this->value = $val; - } - - // Destructor Method - public function __destruct() { - echo "Object is being destroyed."; - } - } - - $obj = new TestClass("Hello World"); - echo $obj->value; - // Displays: Hello World - // And when the script ends, "Object is being destroyed." + +The constructor (`__construct`) is a special method called automatically when an object is instantiated. It initializes the object's properties. The destructor (`__destruct`) runs when the object is no longer referenced and is used to release resources like database connections or file handles. Visit the following resources to learn more: diff --git a/roadmaps/php/content/cookies@so03-fK7E2WvTm6XsPq4i.md b/roadmaps/php/content/cookies@so03-fK7E2WvTm6XsPq4i.md index 55ba7f71e..501868445 100644 --- a/roadmaps/php/content/cookies@so03-fK7E2WvTm6XsPq4i.md +++ b/roadmaps/php/content/cookies@so03-fK7E2WvTm6XsPq4i.md @@ -1,6 +1,6 @@ # Cookies -Cookies are a crucial part of state management in PHP. They enable storage of data on the user's browser, which can then be sent back to the server with each subsequent request. This permits persistent data between different pages or visits. To set a cookie in PHP, you can use the `setcookie()` function. For example, `setcookie("user", "John Doe", time() + (86400 * 30), "/");` will set a cookie named "user" with the value "John Doe", that will expire after 30 days. The cookie will be available across the entire website due to the path parameter set as `/`. To retrieve the value of the cookie, you can use the global `$_COOKIE` array: `echo $_COOKIE["user"];`. +Cookies are small key-value strings stored in the user's browser and sent with every request to the matching domain. PHP sets cookies with `setcookie()` and reads them through `$_COOKIE`. Cookies can have expiration times, domain restrictions, and security flags like `Secure` and `HttpOnly` to limit exposure. Visit the following resources to learn more: diff --git a/roadmaps/php/content/csrf-protection@J9yIXZTtwbFzH2u4dI1ep.md b/roadmaps/php/content/csrf-protection@J9yIXZTtwbFzH2u4dI1ep.md index 1b2246f1c..b2887056b 100644 --- a/roadmaps/php/content/csrf-protection@J9yIXZTtwbFzH2u4dI1ep.md +++ b/roadmaps/php/content/csrf-protection@J9yIXZTtwbFzH2u4dI1ep.md @@ -1,18 +1,6 @@ # CSRF Protection - -Cross-Site Request Forgery (CSRF) Protection in PHP is a method where a website can defend itself against unwanted actions performed on behalf of the users without their consent. It's a critical aspect of security as it safeguards users against potential harmful activities. Here's an example: if users are logged into a website and get tricked into clicking a deceitful link, CSRF attacks could be triggered. To protect your PHP applications from such attacks, you can generate a unique token for every session and include it as a hidden field for all form submissions. Afterwards, you need to verify this token on the server side before performing any action. - - + +Cross-Site Request Forgery (CSRF) tricks authenticated users into submitting unintended requests. The standard defense is generating a unique, unpredictable token per session, embedding it in forms, and validating it on the server when the form is submitted. PHP frameworks typically include built-in CSRF middleware. Visit the following resources to learn more: diff --git a/roadmaps/php/content/csv-processing@MRDjEjbkMpk7shcWAoPOF.md b/roadmaps/php/content/csv-processing@MRDjEjbkMpk7shcWAoPOF.md index ad9ee42ec..2826f1643 100644 --- a/roadmaps/php/content/csv-processing@MRDjEjbkMpk7shcWAoPOF.md +++ b/roadmaps/php/content/csv-processing@MRDjEjbkMpk7shcWAoPOF.md @@ -1,16 +1,6 @@ # CSV Processing -CSV processing refers to handling CSV (Comma Separated Values) files in PHP, an operation significantly useful for managing tabular data. PHP provides a few key functions to handle CSV files effectively. For example, `fgetcsv()` allows you to read CSV file line by line, `fputcsv()` lets you write line by line into a CSV file, and `str_getcsv()` allows you to parse a CSV string into an array. A quick example of reading a CSV file: - - if (($handle = fopen("sample.csv", "r")) !== FALSE) { - while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { - print_r($data); - } - fclose($handle); - } - - -In this snippet, PHP reads through each line of the `sample.csv` file, converting each into an array with `fgetcsv()`. +PHP handles CSV files using `fgetcsv()` to read rows as arrays and `fputcsv()` to write arrays as CSV lines. For reading an entire CSV into memory, `array_map('str_getcsv', file($path))` is a common shortcut. CSV is widely used for data exports and imports between systems. Visit the following resources to learn more: diff --git a/roadmaps/php/content/curl@KC6D81-T-FwQc7Osw1rlY.md b/roadmaps/php/content/curl@KC6D81-T-FwQc7Osw1rlY.md index d2737f0e1..e0d8420fd 100644 --- a/roadmaps/php/content/curl@KC6D81-T-FwQc7Osw1rlY.md +++ b/roadmaps/php/content/curl@KC6D81-T-FwQc7Osw1rlY.md @@ -1,19 +1,6 @@ # cURL - -cURL is a flexible way to make requests to external servers from within a PHP script. cURL, which stands for Client URL, is a library that facilitates various types of network communication methods based on different types of URLs. You can, for example, use cURL functions in PHP to access REST APIs, download files, or post form data, among other things. Here's a basic PHP cURL example where we fetch data from an API: - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, "http://example.com/api/data"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $result = curl_exec($ch); - - if(curl_errno($ch)){ - echo 'Error:' . curl_error($ch); - } - - curl_close($ch); + +cURL is a library for making HTTP and other protocol requests from PHP. The `curl_*` functions allow you to send GET and POST requests, set headers, handle authentication, and follow redirects. cURL is used for consuming REST APIs, fetching remote resources, and integrating with third-party services. Visit the following resources to learn more: diff --git a/roadmaps/php/content/data-types@srIHPZabaCGdB5VvUXaMa.md b/roadmaps/php/content/data-types@srIHPZabaCGdB5VvUXaMa.md index 1ff999d61..d5e0ef055 100644 --- a/roadmaps/php/content/data-types@srIHPZabaCGdB5VvUXaMa.md +++ b/roadmaps/php/content/data-types@srIHPZabaCGdB5VvUXaMa.md @@ -1,11 +1,6 @@ # Data Types -PHP is a flexible and widely-used language that supports several types of data. These types include integers, floating-point numbers, strings, arrays, objects, NULL, and many more. The different data types allow developers to efficiently manage and handle data in their applications. For example, an integer data type in PHP can be a non-decimal number between -2,147,483,648 and 2,147,483,647. Here's a small sample PHP code snippet that assigns different data types to variables: - - $text = "Hello world!"; // String - $number = 1234; // Integer - $decimalNumber = 12.34; // Floating-point number - $boolean = true; // Boolean +PHP supports several data types: integers, floats, strings, booleans, arrays, objects, NULL, and resources. The language is loosely typed, so PHP will automatically convert types when needed. You can check a variable's type using functions like `gettype()` or `is_int()`. Visit the following resources to learn more: diff --git a/roadmaps/php/content/database-migrations@meplwvmHMtI3Sb_fyodzZ.md b/roadmaps/php/content/database-migrations@meplwvmHMtI3Sb_fyodzZ.md index 5e8ff8875..7622af757 100644 --- a/roadmaps/php/content/database-migrations@meplwvmHMtI3Sb_fyodzZ.md +++ b/roadmaps/php/content/database-migrations@meplwvmHMtI3Sb_fyodzZ.md @@ -1,7 +1,3 @@ # Database Migrations - -Database migrations help keep track of changes in your database schema, making it easier to move from one version of a database to another. Migrations allow us to evolve our database design iteratively and apply these updates across our development, staging, and production servers. This can save a lot of manual work. But more than that, migrations maintain consistency across all the environments, reducing the chances of unexpected behavior. There's no standard built-in migrations mechanism in PHP, but powerful and popular PHP frameworks like Laravel have robust solutions for migrations. - -Visit the following resources to learn more: - -* [@article@Laravel Migrations](https://laravel.com/docs/migrations). \ No newline at end of file + +Database migrations are versioned scripts that define incremental changes to a database schema, such as creating tables, adding columns, or modifying indexes. They allow teams to evolve the database schema in a controlled, reproducible way. Tools like Phinx and Laravel's built-in migrator manage migration history and execution order. \ No newline at end of file diff --git a/roadmaps/php/content/default--optional-params@RgVP99rJJ8FVecIA45w20.md b/roadmaps/php/content/default--optional-params@RgVP99rJJ8FVecIA45w20.md index d39ad5c4b..e07a57931 100644 --- a/roadmaps/php/content/default--optional-params@RgVP99rJJ8FVecIA45w20.md +++ b/roadmaps/php/content/default--optional-params@RgVP99rJJ8FVecIA45w20.md @@ -1,13 +1,6 @@ # Default / Optional Params - -In PHP, you can assign default values to your function parameters. These are called default or optional parameters. This is exceptionally useful when you want to make the function argument optional so if a value is not provided when the function is called, then the default value is used instead. Here's a simple code example: - - function greet($name = "guest") { - echo "Hello, $name!"; - } - - greet(); // Outputs: Hello, guest! - greet("John"); // Outputs: Hello, John! + +Default parameter values are assigned in the function signature with `=`. When a caller omits that argument, the default value is used instead. Default values must be constants or expressions, not variables. Parameters with defaults must come after required parameters in the signature. Visit the following resources to learn more: diff --git a/roadmaps/php/content/dependency-injection@KEE50C6lOS4eX8sAbfhYe.md b/roadmaps/php/content/dependency-injection@KEE50C6lOS4eX8sAbfhYe.md index 6928e4f82..167931a9a 100644 --- a/roadmaps/php/content/dependency-injection@KEE50C6lOS4eX8sAbfhYe.md +++ b/roadmaps/php/content/dependency-injection@KEE50C6lOS4eX8sAbfhYe.md @@ -1,28 +1,6 @@ # Dependency Injection - -Dependency injection is a design pattern used mainly for managing class dependencies. Here, instead of a class being responsible for creating its dependencies on its own, an injector (the "client") passes the requirements to the class (the "service"), centralizing control and encouraging code to follow the single responsibility principle. As a simple example, consider a situation where class B needs to utilize class A's methods. Instead of creating an object of class A within B, with dependency injection, we pass an instance of class A to B. - - class A { - function display(){ - echo 'Hello, PHP dependency injection!'; - } - } - - class B { - private $a; - - public function __construct(A $classAInstance) { - $this->a = $classAInstance; - } - - public function callDisplayOwn() { - $this->a->display(); - } - } - - $instanceA = new A(); - $instanceB = new B($instanceA); - $instanceB->callDisplayOwn(); // Outputs: "Hello, PHP dependency injection!" + +Dependency injection (DI) is a design pattern where a class receives its dependencies from outside rather than creating them internally. This makes classes easier to test and reduces coupling. In PHP, DI is typically implemented by passing dependencies through the constructor. DI containers automate this wiring in larger applications. Visit the following resources to learn more: diff --git a/roadmaps/php/content/echo@2ykzBBdYhWuM-neGf0AWP.md b/roadmaps/php/content/echo@2ykzBBdYhWuM-neGf0AWP.md index d85e1765d..7b1e098bd 100644 --- a/roadmaps/php/content/echo@2ykzBBdYhWuM-neGf0AWP.md +++ b/roadmaps/php/content/echo@2ykzBBdYhWuM-neGf0AWP.md @@ -1,10 +1,3 @@ # echo -'echo' is a language construct in PHP, and it is commonly used to output one or more strings to the browser. This command doesn't behave like a function, hence it doesn't require parentheses unless it's necessary to avoid confusion. It's also worth mentioning that 'echo' also supports multiple parameters. Check out a simple example below where we are using echo to output a simple string: - - echo "Hello, world!"; - - -Visit the following resources to learn more: - -* [@official@echo](https://www.php.net/manual/en/function.echo.php). \ No newline at end of file +`echo` outputs one or more strings to the browser or command line. It is a language construct, not a function, so parentheses are optional. `echo` can accept multiple comma-separated arguments and is marginally faster than `print` because it does not return a value. \ No newline at end of file diff --git a/roadmaps/php/content/environment-variables@fitjnLYKLHJ2P5G7JAvzm.md b/roadmaps/php/content/environment-variables@fitjnLYKLHJ2P5G7JAvzm.md index ca80c07ad..2f6d9de3a 100644 --- a/roadmaps/php/content/environment-variables@fitjnLYKLHJ2P5G7JAvzm.md +++ b/roadmaps/php/content/environment-variables@fitjnLYKLHJ2P5G7JAvzm.md @@ -1,16 +1,6 @@ # Environment Variables - -Environment variables provide a way to influence the behavior of software on your system. They consist of name/value pairs and are used for various purposes, such as to specify directory paths, usernames, or passwords that your PHP application might use. You can set PHP environment variables using the `putenv()` function, and retrieve them using `getenv()`. For example, if you want to set the environment variable "FOO" to "bar", you could do so like this: - - putenv("FOO=bar"); - - -And then you can retrieve the value with `getenv()` like: - - echo getenv("FOO"); // returns "bar" - - -Keep in mind that environment variables set using `putenv()` are only available for the duration of the current request. If you want them to persist for future requests, you'll need to set them using your system's method for setting environment variables. + +Environment variables are key-value pairs set in the server environment and accessed in PHP via `$_ENV`, `getenv()`, or `$_SERVER`. They are the standard way to separate configuration from code, especially for secrets, database credentials, and feature flags. Libraries like Dotenv load `.env` files into the environment during local development. Visit the following resources to learn more: diff --git a/roadmaps/php/content/executing-system-commands@VhyYNGhOdKKrz_-uTkrjD.md b/roadmaps/php/content/executing-system-commands@VhyYNGhOdKKrz_-uTkrjD.md index 0042d5328..183100527 100644 --- a/roadmaps/php/content/executing-system-commands@VhyYNGhOdKKrz_-uTkrjD.md +++ b/roadmaps/php/content/executing-system-commands@VhyYNGhOdKKrz_-uTkrjD.md @@ -1,14 +1,6 @@ # Executing System Commands - -PHP provides developers with the flexibility to invoke system commands directly from PHP scripts. This can be achieved with functions like `exec()`, `system()`, or `passthru()`, which allow your PHP script to execute system-level instructions and interact with the underlying server. This can be useful in several scenarios - for automating tasks, orchestrating system activities, or even for pulling out system information. However, it's important to use these functions with caution due to the security risks of executing system commands. Here's a simple example of using the exec() function: - - + +PHP can run shell commands using functions like `exec()`, `shell_exec()`, `system()`, and `passthru()`. Each differs in how it captures and returns output. User input must never be passed unsanitized to these functions, as it can lead to command injection. `escapeshellarg()` and `escapeshellcmd()` help sanitize arguments safely. Visit the following resources to learn more: diff --git a/roadmaps/php/content/file-permissions@tgIyG6vHWpe9sz6lHmj5a.md b/roadmaps/php/content/file-permissions@tgIyG6vHWpe9sz6lHmj5a.md index 872541dc2..32ffa7f83 100644 --- a/roadmaps/php/content/file-permissions@tgIyG6vHWpe9sz6lHmj5a.md +++ b/roadmaps/php/content/file-permissions@tgIyG6vHWpe9sz6lHmj5a.md @@ -1,6 +1,6 @@ # File Permissions -File permissions in PHP control who can read, write, and execute a file. They're crucial for the security and proper functioning of your PHP applications. When working with files, you can use functions like `chmod()`, `is_readable()`, and `is_writable()` to manage permissions. Typically, you would use `chmod()` to change the permissions of a file. The first parameter is the name of the file and the second parameter is the mode. For instance, `chmod($file, 0755)` would assign owner permissions to read, write, and execute, while everyone else would only have read and execute permissions. To know if a file is readable or writable, use `is_readable()` or `is_writable()` respectively. +File permissions control who can read, write, or execute a file. PHP uses `chmod()` to set permissions programmatically and `fileperms()` to read them. On Unix-based systems, permissions follow the standard owner/group/other model. Incorrect permissions are a common cause of file operation errors in PHP applications. Visit the following resources to learn more: diff --git a/roadmaps/php/content/file-uploads@HNo8QO4aPbvgePiA4l6tq.md b/roadmaps/php/content/file-uploads@HNo8QO4aPbvgePiA4l6tq.md index 994faf2d7..e61889e27 100644 --- a/roadmaps/php/content/file-uploads@HNo8QO4aPbvgePiA4l6tq.md +++ b/roadmaps/php/content/file-uploads@HNo8QO4aPbvgePiA4l6tq.md @@ -1,8 +1,6 @@ # File Uploads -Uploading files in PHP is a commonly used functionality for many applications. This is typically done using the `$_FILES` superglobal array that allows you to manage uploaded files in your PHP script. It contains details like `name`, `type`, `size` etc of the file. An index is also present for each file in the case of multiple uploads. The `move_uploaded_file()` function is then used to move the uploaded file to the desired directory. - -Don't forget to pay attention to security considerations when accepting file uploads. +PHP handles file uploads through the `$_FILES` superglobal, which contains metadata about each uploaded file including its name, type, size, temporary path, and error code. Files are moved from the temp directory to a permanent location using `move_uploaded_file()`. Upload size limits are configured in `php.ini`. Visit the following resources to learn more: diff --git a/roadmaps/php/content/form-processing@sYI7f1PYP7G30_Uj2mZRv.md b/roadmaps/php/content/form-processing@sYI7f1PYP7G30_Uj2mZRv.md index 03f8f8813..170fefbab 100644 --- a/roadmaps/php/content/form-processing@sYI7f1PYP7G30_Uj2mZRv.md +++ b/roadmaps/php/content/form-processing@sYI7f1PYP7G30_Uj2mZRv.md @@ -1,8 +1,6 @@ # Form Processing -Form processing is a common web function and in PHP, it's pretty straightforward. It typically involves accepting data from a user through a web form and then using PHP to handle, process and possibly store that data. PHP provides superglobal arrays (`$_GET`, `$_POST`, and `$_REQUEST`) which help to collect form data. Let's talk about a simple example of a form that accepts a name from a user and then displays it. - -Make sure to handle form data securely, for instance by using the `htmlspecialchars()` function to neutralize any harmful characters. +Form processing in PHP involves reading submitted input from `$_GET` or `$_POST`, validating and sanitizing the values, and then performing an action such as saving to a database or sending an email. The Post/Redirect/Get (PRG) pattern is commonly used to prevent duplicate form submissions on page reload. Visit the following resources to learn more: diff --git a/roadmaps/php/content/function-declaration@1nODJchgSuWbcvSlxnWeE.md b/roadmaps/php/content/function-declaration@1nODJchgSuWbcvSlxnWeE.md index 65091b818..e71cfb025 100644 --- a/roadmaps/php/content/function-declaration@1nODJchgSuWbcvSlxnWeE.md +++ b/roadmaps/php/content/function-declaration@1nODJchgSuWbcvSlxnWeE.md @@ -1,13 +1,6 @@ # Function Declaration - -Function is the block of code that performs a specific task. It is a reusable code that can be called multiple times. In PHP, a function is declared using the `function` keyword followed by the function name and parentheses. The function name should be unique and descriptive. The parentheses may contain parameters that are passed to the function. The function body is enclosed within curly braces `{}`. - - function greeting($name) { - echo "Hello, " . $name; - } - - -In this case, 'greeting' is the function name, '$name' is the parameter, and 'echo "Hello, " . $name;' is the operation. + +A function is declared using the `function` keyword, followed by the function name, parentheses for parameters, and a code block. Function names are case-insensitive in PHP. Functions can be defined anywhere in a file and are available throughout the script scope once declared. Visit the following resources to learn more: diff --git a/roadmaps/php/content/functions@WiGv7vi7Mtw-YqPMcnnyw.md b/roadmaps/php/content/functions@WiGv7vi7Mtw-YqPMcnnyw.md index 76e629606..06e52aab1 100644 --- a/roadmaps/php/content/functions@WiGv7vi7Mtw-YqPMcnnyw.md +++ b/roadmaps/php/content/functions@WiGv7vi7Mtw-YqPMcnnyw.md @@ -1,15 +1,6 @@ # Functions - -Functions in PHP are self-contained blocks of code that carry out specific tasks and can be reused throughout your application. A function is defined with the word "function" followed by a name, and it should return a value using the "return" statement. To use a function, you simply need to call it by its name. You can also pass parameters to functions to influence how they work. Here's a simple function: - - function greet($name) { - return "Hello, " . $name; - } - - echo greet("John"); // Outputs: Hello, John - - -In the code above, "greet" is a function that takes one parameter "name". It concatenates "Hello, " with the name and returns the result. + +Functions are reusable blocks of code defined with the `function` keyword. They encapsulate logic, accept parameters, and can return values. PHP includes a large standard library of built-in functions, and you can define your own. Functions in PHP support default parameters, variadic arguments, type declarations, and named arguments. Visit the following resources to learn more: diff --git a/roadmaps/php/content/http-methods@tn_iIfaJZVtPK6vFds7FH.md b/roadmaps/php/content/http-methods@tn_iIfaJZVtPK6vFds7FH.md index 129bc494c..1e6994b8b 100644 --- a/roadmaps/php/content/http-methods@tn_iIfaJZVtPK6vFds7FH.md +++ b/roadmaps/php/content/http-methods@tn_iIfaJZVtPK6vFds7FH.md @@ -1,6 +1,6 @@ # HTTP Methods -PHP allows for handling HTTP methods, which are a way of defining the action to be performed on the resource identified by a given URL. In PHP, the $\_SERVER superglobal array can be used to identify the HTTP method of a specific request, typically a GET, POST, PUT, DELETE or HEAD. For example, to identify if a request is a POST request, you can use `if ($_SERVER['REQUEST_METHOD'] == 'POST') { // your code here }`. More advanced handling can be done by utilizing built-in PHP libraries or third-party packages. +HTTP defines methods that indicate the intended action for a request. GET retrieves data, POST submits data, PUT replaces a resource, PATCH updates part of a resource, and DELETE removes a resource. PHP primarily handles GET and POST natively through superglobals; other methods are read from `$_SERVER['REQUEST_METHOD']` and the request body. Visit the following resources to learn more: diff --git a/roadmaps/php/content/ifelse@-McOv-ZPTGayX7Mx2Thw1.md b/roadmaps/php/content/ifelse@-McOv-ZPTGayX7Mx2Thw1.md index b728b5df1..682e6eef1 100644 --- a/roadmaps/php/content/ifelse@-McOv-ZPTGayX7Mx2Thw1.md +++ b/roadmaps/php/content/ifelse@-McOv-ZPTGayX7Mx2Thw1.md @@ -1,16 +1,6 @@ # if/else - -In PHP, the if/else conditional statements are fundamental components that control the flow of the program based on specific conditions. When the 'if' condition is true, a block of code will execute. If that condition is not met (or false), the program proceeds to the 'else' statement (if provided), executing its block of code. This allows you to handle different situations dynamically. A simple example of this concept in action would be: - - $number = 10; - if ($number > 5) { - echo "The number is greater than 5"; - } else { - echo "The number is not greater than 5"; - } - - -In this example, the output will be "The number is greater than 5" because the condition evaluated to true. + +The `if/else` structure executes a block of code when a condition is true and a different block when it is false. `elseif` adds additional conditions to check in sequence. PHP also supports a shorthand `if` using the ternary operator (`? :`). Visit the following resources to learn more: diff --git a/roadmaps/php/content/include@hKfv7V6bl2LXssq9Ffi7C.md b/roadmaps/php/content/include@hKfv7V6bl2LXssq9Ffi7C.md index ef272bcae..02a993f70 100644 --- a/roadmaps/php/content/include@hKfv7V6bl2LXssq9Ffi7C.md +++ b/roadmaps/php/content/include@hKfv7V6bl2LXssq9Ffi7C.md @@ -1,13 +1,6 @@ # include - -The 'include' statement in PHP is a useful method for inserting code written in one file into another. It's mainly used when the same code needs to be used in multiple files, avoiding redundancy and making code maintenance easier. If it cannot find the file, PHP will emit a warning but continue to execute the rest of the script. Here's a simple example: - - - - -In this code snippet, 'filename.php' is the file containing the code that you want to insert. Just replace 'filename.php' with the actual file path you want to include. + +`include` inserts the contents of another PHP file into the current script. If the file is not found, PHP emits a warning but continues execution. It is appropriate when the included file is optional and the script can still function without it. Visit the following resources to learn more: diff --git a/roadmaps/php/content/include_once@SwtLDgyPmDry20qS4FBfH.md b/roadmaps/php/content/include_once@SwtLDgyPmDry20qS4FBfH.md index fcb8b906c..ecba1d4dc 100644 --- a/roadmaps/php/content/include_once@SwtLDgyPmDry20qS4FBfH.md +++ b/roadmaps/php/content/include_once@SwtLDgyPmDry20qS4FBfH.md @@ -1,13 +1,6 @@ # include_once - -The `include_once` statement is a part of PHP's file-handling toolkit, allowing developers to include a PHP file within another PHP file, but only for a one-time execution. This way, you can ensure that functions or objects defined in the included file are not duplicated leading to errors. It helps keep your code DRY (Don't Repeat Yourself) and clean. Here is a small example: - - include_once 'database.php'; - - $db = new Database(); - - -In this simple code snippet, we include the `database.php` file once, giving us access to the `Database` class. + +`include_once` works like `include` but skips inclusion if the file has already been loaded. It avoids redeclaring functions or classes when the same file is referenced multiple times across a codebase. It emits a warning rather than a fatal error if the file is not found. Visit the following resources to learn more: diff --git a/roadmaps/php/content/indexed-arrays@j2S8dP3HlAOOoZdpj-7Dx.md b/roadmaps/php/content/indexed-arrays@j2S8dP3HlAOOoZdpj-7Dx.md index ee6367ce2..973621ff8 100644 --- a/roadmaps/php/content/indexed-arrays@j2S8dP3HlAOOoZdpj-7Dx.md +++ b/roadmaps/php/content/indexed-arrays@j2S8dP3HlAOOoZdpj-7Dx.md @@ -1,11 +1,6 @@ # Indexed Arrays - -Indexed arrays in PHP store values that are accessed through numerical indexes, which start at 0 by default. This might be particularly useful when you have a list of items in a specific order. For example, you might use an indexed array to represent a list of your favorite books, where each book is numbered starting from 0. Each individual item in the array, book in this case, can be accessed by their specific index. You can use the array() function or the short array syntax \[\] to declare an indexed array. - -Here's an Example: - - $books = ["The Great Gatsby", "Moby Dick", "To Kill a Mockingbird"]; - echo $books[0]; //Outputs "The Great Gatsby" + +Indexed arrays use numeric keys starting at zero. Values are accessed by their position, like `$arr[0]`. PHP assigns numeric keys automatically when you add items without specifying a key. Functions like `sort()` and `array_reverse()` work directly on indexed arrays. Visit the following resources to learn more: diff --git a/roadmaps/php/content/inheritance@c5q2e_jyMt8Pir5Od3lRi.md b/roadmaps/php/content/inheritance@c5q2e_jyMt8Pir5Od3lRi.md index 347ea1c25..a41f4472f 100644 --- a/roadmaps/php/content/inheritance@c5q2e_jyMt8Pir5Od3lRi.md +++ b/roadmaps/php/content/inheritance@c5q2e_jyMt8Pir5Od3lRi.md @@ -1,26 +1,6 @@ # Inheritance - -Inheritance, a fundamental concept in object-oriented programming (OOP), is a feature that PHP supports. It lets us create classes which are extensions of other classes, inheriting their methods and properties. This concept allows the creation of more flexible and maintainable code, as it promotes code reuse. For instance, consider we have a 'Vehicle' class and we want to create a 'Car' class. Since cars are a type of vehicle, it would make sense for our 'Car' class to inherit from the 'Vehicle' class. - - class Vehicle { - public $color; - function drive() { - echo "Driving..."; - } - } - - class Car extends Vehicle { - function horn() { - echo "Beeping..."; - } - } - - $myCar = new Car(); - $myCar->drive(); // Inherits drive method from Vehicle - $myCar->horn(); // Unique to Car - - -In the above example, the 'Car' class inherits the drive method from the 'Vehicle' class but also has an additional method, horn. This is an illustration of how inheritance in PHP can help to organize your code efficiently and intuitively. + +Inheritance allows a class to extend another class, inheriting its properties and methods. The child class uses `extends` and can override parent methods or add new ones. PHP supports single inheritance only. The `parent::` keyword calls the parent class's method from the child class. Visit the following resources to learn more: diff --git a/roadmaps/php/content/input-validation@93oEIZttb85S23C1fLraP.md b/roadmaps/php/content/input-validation@93oEIZttb85S23C1fLraP.md index 64c1e928a..1e3b466fa 100644 --- a/roadmaps/php/content/input-validation@93oEIZttb85S23C1fLraP.md +++ b/roadmaps/php/content/input-validation@93oEIZttb85S23C1fLraP.md @@ -1,15 +1,6 @@ # Input Validation - -Input validation is a vital aspect of PHP security. It involves checking whether the user-provided data is in the expected format or not before it's processed further. This helps prevent potential security risks such as SQL injections, cross-site scripting (XSS) etc. Let's take an example of a simple form input validation: - - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { - echo("Email is valid"); - } else { - echo("Email is not valid"); - } - - -This code uses PHP's built-in `filter_var()` function to ensure the data is a valid email address. If not, the form will not be submitted until valid data is entered. + +Input validation checks that user-supplied data conforms to expected formats and constraints before processing it. PHP's `filter_var()` function supports filters for emails, URLs, integers, floats, and IP addresses. Custom validation logic handles domain-specific rules like password strength or username format. Visit the following resources to learn more: diff --git a/roadmaps/php/content/interfaces@vu0H-TsD7hkJgOQbSRj92.md b/roadmaps/php/content/interfaces@vu0H-TsD7hkJgOQbSRj92.md index 959d4d675..239e6f4d3 100644 --- a/roadmaps/php/content/interfaces@vu0H-TsD7hkJgOQbSRj92.md +++ b/roadmaps/php/content/interfaces@vu0H-TsD7hkJgOQbSRj92.md @@ -1,28 +1,6 @@ # Interfaces - -Interfaces in PHP serve as a blueprint for designing classes. They ensure that a class adheres to a certain contract, all without defining how those methods should function. As PHP is not a strictly typed language, interfaces can be particularly useful in large codebases to maintain continuity and predictability. For example, in PHP, an interface 'iTemplate' could be defined with methods 'setVariable' and 'getHtml'. Any class that implements this interface must define these methods. - -Here is a snippet: - - interface iTemplate { - public function setVariable($name, $var); - public function getHtml($template); - } - - class Template implements iTemplate { - private $vars = array(); - - public function setVariable($name, $var) { - $this->vars[$name] = $var; - } - - public function getHtml($template) { - foreach($this->vars as $name => $value) { - $template = str_replace('{' . $name . '}', $value, $template); - } - return $template; - } - } + +Interfaces define a contract of methods that implementing classes must provide. A class can implement multiple interfaces, unlike inheritance which is limited to a single parent. Interfaces contain only method signatures and constants, no implementations. They are used to define capabilities that unrelated classes can share. Visit the following resources to learn more: diff --git a/roadmaps/php/content/introduction-to-php@_hYN0gEi9BL24nptEtXWU.md b/roadmaps/php/content/introduction-to-php@_hYN0gEi9BL24nptEtXWU.md index df8d782f2..a45f5e94d 100644 --- a/roadmaps/php/content/introduction-to-php@_hYN0gEi9BL24nptEtXWU.md +++ b/roadmaps/php/content/introduction-to-php@_hYN0gEi9BL24nptEtXWU.md @@ -1,15 +1,6 @@ # Introduction to PHP -PHP, also known as Hypertext Preprocessor, is a powerful scripting language used predominantly for creating dynamic web pages and applications. It provides seamless interaction with databases, easier control of content, session tracking, and cookies. Being an open-source language, it's favored by developers for its flexibility, speed, and security. - -Here's a simple PHP code to print a text: - - - - -Here the "echo" command in PHP helps to output one or more strings. +PHP (Hypertext Preprocessor) is a server-side scripting language designed primarily for web development. It runs on the server and generates HTML that is sent to the client's browser. PHP powers a large portion of the web, including platforms like WordPress and Facebook's early codebase. Visit the following resources to learn more: diff --git a/roadmaps/php/content/json-processing@DB2cxZE58WCCavW2PNwmf.md b/roadmaps/php/content/json-processing@DB2cxZE58WCCavW2PNwmf.md index 4d5f9f3d5..4acb021ce 100644 --- a/roadmaps/php/content/json-processing@DB2cxZE58WCCavW2PNwmf.md +++ b/roadmaps/php/content/json-processing@DB2cxZE58WCCavW2PNwmf.md @@ -1,21 +1,6 @@ # JSON Processing -JSON Processing in PHP refers to the handling, reading, and manipulation of JSON formatted data. JSON, or JavaScript Object Notation, is a versatile data format used worldwide due to its easy readability and robustness. PHP natively supports JSON and includes built-in functions like `json_encode()` and `json_decode()`. The `json_encode()` function returns a JSON representation of a value, particularly useful when you need to pass arrays or objects to a script. On the other hand, `json_decode()` is used to extract data from a JSON file or a JSON-encoded string, converting it into a PHP variable. Here's a quick example: - - // Create an array - $data = array('a' => 1, 'b' => 2, 'c' => 3); - - // Encode the array into a JSON string - $json = json_encode($data); - echo $json; - - // Output: {"a":1,"b":2,"c":3} - - // Decode the JSON string back into an array - $decoded = json_decode($json, true); - print_r($decoded); - - // Output: Array ( [a] => 1 [b] => 2 [c] => 3 ) +PHP encodes data to JSON with `json_encode()` and decodes JSON strings with `json_decode()`. `json_decode()` returns an object by default or an associative array when the second argument is `true`. JSON is the standard format for exchanging data between PHP backends and JavaScript frontends or external APIs. Visit the following resources to learn more: diff --git a/roadmaps/php/content/lamp@7LjxtrmgJtTJc0_kP83Tr.md b/roadmaps/php/content/lamp@7LjxtrmgJtTJc0_kP83Tr.md index 02f0631b0..54a529dbb 100644 --- a/roadmaps/php/content/lamp@7LjxtrmgJtTJc0_kP83Tr.md +++ b/roadmaps/php/content/lamp@7LjxtrmgJtTJc0_kP83Tr.md @@ -1,6 +1,6 @@ # LAMP -LAMP refers to the combined use of Linux OS, Apache HTTP Server, MySQL relational database management system, and PHP; it's a popular stack for creating and hosting websites. For PHP, LAMP is a robust, open-source web development platform that supports a wide range of dynamic websites and applications. Suppose you plan to develop a content management system (CMS), forums, or e-commerce shops. In that case, PHP, as a part of the LAMP stack, helps provide a flexible development environment. Here, PHP works hand-in-hand with MySQL to access and manage databases, get queried results, and embed them into HTML pages by the Apache HTTP Server before sending them to the client side. +LAMP stands for Linux, Apache, MySQL, and PHP. It is a widely used open-source web server stack for deploying PHP applications in production. Each component handles a specific role: Linux as the OS, Apache as the web server, MySQL for the database, and PHP for server-side logic. Visit the following resources to learn more: diff --git a/roadmaps/php/content/loops@qwt8xN4vuTrY-D0czYITI.md b/roadmaps/php/content/loops@qwt8xN4vuTrY-D0czYITI.md index 3f973ff8f..415d0c31d 100644 --- a/roadmaps/php/content/loops@qwt8xN4vuTrY-D0czYITI.md +++ b/roadmaps/php/content/loops@qwt8xN4vuTrY-D0czYITI.md @@ -1,15 +1,6 @@ # Loops - -PHP incorporates the use of loops, which are a vital part of programming. They allow a block of code to be executed repeatedly based on a certain condition or until a specific condition is met. In PHP, there are four types of loops - 'while', 'do-while', 'for' and 'foreach'. The 'while' loop continues executing its nested code as long as the condition remains true. The 'do-while' loop executes a block of code at least once, and then either continues executing it or stops, based on the condition. The 'for' loop is often used when the number of iterations is known. The 'foreach' loop works with arrays and is used to loop through each key/value pair in an array. Here's a simple example of a 'for' loop in PHP: - - - - -In this example, the loop will execute five times, with $i increasing by one each time, outputting the numbers from 0 to 4. + +Loops repeat a block of code multiple times. PHP supports four loop types: `while`, `do...while`, `for`, and `foreach`. The right choice depends on whether you know the iteration count in advance and whether you're iterating over a sequence or a condition. `break` exits a loop early; `continue` skips to the next iteration. Visit the following resources to learn more: diff --git a/roadmaps/php/content/magic-methods@rSXsPWto7Jeyw3Szl9pvf.md b/roadmaps/php/content/magic-methods@rSXsPWto7Jeyw3Szl9pvf.md index 6bee5a39b..654b1d390 100644 --- a/roadmaps/php/content/magic-methods@rSXsPWto7Jeyw3Szl9pvf.md +++ b/roadmaps/php/content/magic-methods@rSXsPWto7Jeyw3Szl9pvf.md @@ -1,15 +1,6 @@ -# Magic methods - -PHP Magic Methods, often considered the hooks of the language, provide developers a way to change how objects will respond to particular language constructs. Magic methods are special functions that start with "\_\_" such as `__construct()`, `__destruct(), __call(), __get(), __set()` and more. They enable us to perform certain tasks automatically when specific actions occur. For example, `__construct()` executes when an object is created while `__destruct()` triggers when an object is no longer needed. Let's see the `__construct` magic method in action: - - class Car { - public $color; - public function __construct($color) { - $this->color = $color; - } - } - $blueCar = new Car("Blue"); // This will call the __construct() method. - echo $blueCar->color; // Outputs "Blue". +# Magic Methods + +Magic methods are special PHP methods with double-underscore prefixes that are triggered automatically in response to specific events. Common ones include `__construct`, `__toString`, `__get`, `__set`, `__call`, and `__invoke`. They allow classes to define custom behavior for object creation, property access, method calls, and more. Visit the following resources to learn more: diff --git a/roadmaps/php/content/mamp@t7p7TU2khaxsZPYAdwFAA.md b/roadmaps/php/content/mamp@t7p7TU2khaxsZPYAdwFAA.md index 75854b8a7..59f92b112 100644 --- a/roadmaps/php/content/mamp@t7p7TU2khaxsZPYAdwFAA.md +++ b/roadmaps/php/content/mamp@t7p7TU2khaxsZPYAdwFAA.md @@ -1,6 +1,6 @@ # MAMP -MAMP stands for Macintosh, Apache, MySQL, and PHP. It is a popular software stack that enables developers to run a local server environment. While other technology stacks might be more relevant to different languages or platform-specific development, MAMP is highly beneficial for PHP development. MAMP allows PHP developers to run their code in a localhost environment on their systems, making testing and debugging more straightforward. MAMP bundles all the required software packages (Apache, MySQL, PHP) into one convenient installation, supporting developers in creating a reliable, consistent development environment without tussle. However, as an assistant, I cannot provide a code sample for this topic since it's not directly related to coding in PHP. +MAMP (Mac, Apache, MySQL, PHP) is a local server environment designed for macOS, though a Windows version also exists. It packages Apache or Nginx, MySQL, and PHP together and provides a graphical interface for managing them. MAMP Pro adds virtual hosts, dynamic DNS, and other features for professional use. Visit the following resources to learn more: diff --git a/roadmaps/php/content/match@3gNzX-bw2iqur7U7-_W38.md b/roadmaps/php/content/match@3gNzX-bw2iqur7U7-_W38.md index 13428a15a..4fdfbc60b 100644 --- a/roadmaps/php/content/match@3gNzX-bw2iqur7U7-_W38.md +++ b/roadmaps/php/content/match@3gNzX-bw2iqur7U7-_W38.md @@ -1,15 +1,6 @@ # match - -Match expressions are an integral feature of PHP, introduced in PHP 8.0 as an alternative to the switch statement. Compared to the switch statement, match expressions are safer since they don't require break statements and are more concise. The match expression can be an excellent tool for pattern matching. Here's an example: - - $message = match ($statusCode) { - 200, 300 => 'OK', - 400 => 'error', - default => 'unknown status code', - }; - - -In this code, based on the value of `$statusCode`, the `match` expression assigns a specific text to the `$message`. If `$statusCode` is not 200, 300, or 400, the `default` case applies. After running the code, the `$message` variable contains the result of the `match` expression. + +The `match` expression works like `switch` but uses strict comparison (`===`) and returns a value rather than executing statements. Each arm maps one or more conditions to an expression. Unlike `switch`, there is no fall-through, and if no arm matches, PHP throws an `UnhandledMatchError`. Visit the following resources to learn more: diff --git a/roadmaps/php/content/memory-management@bt7dK2PcOZ72B9HXPyMwL.md b/roadmaps/php/content/memory-management@bt7dK2PcOZ72B9HXPyMwL.md index 6dcbeb3dc..8e075abba 100644 --- a/roadmaps/php/content/memory-management@bt7dK2PcOZ72B9HXPyMwL.md +++ b/roadmaps/php/content/memory-management@bt7dK2PcOZ72B9HXPyMwL.md @@ -1,18 +1,6 @@ # Memory Management - -Memory Management is a crucial part of PHP performance optimization. Efficient memory use can significantly boost the speed and reliability of your PHP applications. PHP automatically provides a garbage collector which cleans up unused memory, but understanding and managing your script's memory usage can result in better use of resources. For instance, `unset()` function can help in freeing up memory by destroying the variables that are no longer used. Here is an example: - - $string = str_repeat("very long string", 10240); - echo memory_get_usage(); // Outputs: 514576 - unset($string); - echo memory_get_usage(); // Outputs: 346672 - - -In this example, memory usage decreases after the `$string` variable is unset. This occurs because `unset()` decreases the reference count, and when it reaches zero, the memory associated with the variable is freed and returned to PHP’s internal memory manager. - -However, this memory is not necessarily returned to the operating system. Instead, it remains allocated to PHP and can be reused for subsequent operations within the script. - -Avoiding unnecessary data storage and leveraging built-in PHP functions can help improve memory efficiency. + +PHP allocates and frees memory automatically, but developers can influence it. The `memory_limit` directive in `php.ini` caps memory per request. Unset large variables with `unset()` when no longer needed. For long-running scripts or batch jobs, careful object lifecycle management prevents memory exhaustion. Visit the following resources to learn more: diff --git a/roadmaps/php/content/multi-dimensional-arrays@uARTOZ-ZwugSmbCJoRS5Y.md b/roadmaps/php/content/multi-dimensional-arrays@uARTOZ-ZwugSmbCJoRS5Y.md index 1fb37a8df..72151e158 100644 --- a/roadmaps/php/content/multi-dimensional-arrays@uARTOZ-ZwugSmbCJoRS5Y.md +++ b/roadmaps/php/content/multi-dimensional-arrays@uARTOZ-ZwugSmbCJoRS5Y.md @@ -1,14 +1,6 @@ # Multi-dimensional Arrays - -Multi-dimensional arrays in PHP are a type of array that contains one or more arrays. Essentially, it's an array of arrays. This allows you to store data in a structured manner, much like a table or a matrix. The fundamental idea is that each array value can, in turn, be another array. For instance, you can store information about various users, where each user (a primary array element) contains several details about them (in a secondary array like email, username etc.). - -Here's an example: - - $users = [ - ["John", "john@example.com", "john123"], - ["Jane", "jane@example.com", "jane123"], - ["Doe", "doe@example.com", "doe123"] - ]; + +Multi-dimensional arrays contain other arrays as values, creating a nested structure. They are used to represent tables, grids, or grouped data. Access follows chained bracket notation: `$matrix[0][1]`. PHP does not limit nesting depth, though deep nesting can make code harder to read. Visit the following resources to learn more: diff --git a/roadmaps/php/content/mysqli@YLuo0oZJzTCoiZoOSG57z.md b/roadmaps/php/content/mysqli@YLuo0oZJzTCoiZoOSG57z.md index aa493c147..1b8e461f7 100644 --- a/roadmaps/php/content/mysqli@YLuo0oZJzTCoiZoOSG57z.md +++ b/roadmaps/php/content/mysqli@YLuo0oZJzTCoiZoOSG57z.md @@ -1,22 +1,6 @@ -# MySQLi - -MySQLi is a PHP extension that allows PHP programs to connect with MySQL databases. This extension provides the capability to perform queries, retrieve data, and perform complex operations on MySQL databases using PHP. MySQLi comes with an object-oriented and procedural interface and supports prepared statements, multiple statements, and transactions. - -Here's a basic example of using MySQLi to connect to a MySQL database: - - $servername = "localhost"; - $username = "username"; - $password = "password"; - $dbname = "myDB"; - - // Create connection - $conn = new mysqli($servername, $username, $password, $dbname); - - // Check connection - if ($conn->connect_error) { - die("Connection failed: " . $conn->connect_error); - } - echo "Connected successfully"; +# Database Connectivity > MySQLi + +MySQLi is a MySQL-specific database extension that offers both procedural and object-oriented APIs. Like PDO, it supports prepared statements and bound parameters. MySQLi provides access to MySQL-specific features and is faster than PDO for MySQL-only applications in some benchmarks. Visit the following resources to learn more: diff --git a/roadmaps/php/content/named-arguments@RkNjYva8o_jXp9suz5YdG.md b/roadmaps/php/content/named-arguments@RkNjYva8o_jXp9suz5YdG.md index 61c0311ad..27b171fa0 100644 --- a/roadmaps/php/content/named-arguments@RkNjYva8o_jXp9suz5YdG.md +++ b/roadmaps/php/content/named-arguments@RkNjYva8o_jXp9suz5YdG.md @@ -1,12 +1,6 @@ # Named Arguments - -Named arguments in PHP, introduced with PHP 8.0, allow you to specify the values of required parameters by their names, instead of their position in the function call, thus making your code more readable, reducing mistakes, and allowing for unimportant arguments to be skipped. Here's an array\_fill() function using named arguments: - - setName('New Product'); - $entityManager->persist($product); - $entityManager->flush(); + +An ORM maps database tables to PHP classes and rows to objects, allowing you to interact with the database using object-oriented code instead of raw SQL. Doctrine is the most widely used PHP ORM; Laravel's Eloquent is another popular option. ORMs handle query building, relationships, and schema mapping automatically. Visit the following resources to learn more: diff --git a/roadmaps/php/content/oop-fundamentals@yTviiPFR5b_dr3WyxdxxQ.md b/roadmaps/php/content/oop-fundamentals@yTviiPFR5b_dr3WyxdxxQ.md index 6687244e0..983b43fc5 100644 --- a/roadmaps/php/content/oop-fundamentals@yTviiPFR5b_dr3WyxdxxQ.md +++ b/roadmaps/php/content/oop-fundamentals@yTviiPFR5b_dr3WyxdxxQ.md @@ -1,19 +1,6 @@ # OOP Fundamentals - -In PHP, Object-Oriented Programming (OOP) Fundamentals cover critical aspects like classes, objects, properties, and methods. OOP facilitates efficient code reusability and makes it easier to manage and modify code. For example, here's a code snippet that represents a class with a method and a property in PHP: - - class Hello { - public $greeting = "Hello, world!"; - - public function displayGreeting() { - echo $this->greeting; - } - } - $hello = new Hello(); - $hello->displayGreeting(); // Outputs "Hello, world!" - - -This snippet defines a class `Hello` with a property `$greeting` and a method `displayGreeting()`. Instances of this class can access these methods and properties. OOP Fundamentals in PHP are much more comprehensive, encompassing concepts like inheritance, encapsulation, and polymorphism. + +Object-Oriented Programming (OOP) in PHP organizes code around classes and objects. A class defines properties and methods; an object is an instance of a class. OOP enables encapsulation, inheritance, and polymorphism, making large codebases easier to organize and maintain. Visit the following resources to learn more: diff --git a/roadmaps/php/content/opcode-caching@NieqZd1juaNYoZOrB7e31.md b/roadmaps/php/content/opcode-caching@NieqZd1juaNYoZOrB7e31.md index f32551e1c..2d1abac85 100644 --- a/roadmaps/php/content/opcode-caching@NieqZd1juaNYoZOrB7e31.md +++ b/roadmaps/php/content/opcode-caching@NieqZd1juaNYoZOrB7e31.md @@ -1,13 +1,6 @@ # Opcode Caching - -Opcode caching is a technique that can significantly enhance the PHP performance. It works by storing precompiled script bytecode in memory, thus eliminating the need for PHP to load and parse scripts on each request. For opcode caching, OPCache extension is often used in PHP. With this, the PHP script's compiled version is stored for subsequent requests, reducing the overhead of code parsing and compiling. As a result, your applications experience faster execution and lower CPU usage. - -An Example of a way to enable OPCache in your php.ini configuration file might look like: - - opcache.enable=1 - opcache.memory_consumption=128 - opcache.max_accelerated_files=4000 - opcache.revalidate_freq=60 + +Opcode caching stores the compiled bytecode of PHP scripts in memory so subsequent requests skip the parsing and compilation step. OPcache is the built-in PHP opcode cache and is enabled by default in modern PHP. It significantly reduces CPU usage and response time for applications serving repeated requests. Visit the following resources to learn more: diff --git a/roadmaps/php/content/parameters--return-values@mpQKoBzsOa-5iWo08sOhQ.md b/roadmaps/php/content/parameters--return-values@mpQKoBzsOa-5iWo08sOhQ.md index 8da7ac2e2..00b519f93 100644 --- a/roadmaps/php/content/parameters--return-values@mpQKoBzsOa-5iWo08sOhQ.md +++ b/roadmaps/php/content/parameters--return-values@mpQKoBzsOa-5iWo08sOhQ.md @@ -1,16 +1,6 @@ # Parameters / Return Values - -Parameters in PHP functions specify the input that the function expects to receive when it is called. They can be of various types like strings, integers, arrays, or even objects. PHP also supports default values for parameters and passing by reference. In PHP, the 'return' statement is often used to end the execution of a function and send back a value. Return values can be any data type. Here's a simple example: - - function addNumbers($num1, $num2) { - $sum = $num1 + $num2; - return $sum; - } - - echo addNumbers(3, 4); // Outputs: 7 - - -In the above code, `$num1` and `$num2` are parameters, and the sum of these numbers is the return value. + +Parameters are variables listed in the function signature that receive values when the function is called. PHP passes arguments by value by default, meaning changes inside the function don't affect the original variable. Prefixing a parameter with `&` passes it by reference. The `return` statement sends a value back to the caller. Visit the following resources to learn more: diff --git a/roadmaps/php/content/password-hashing@JbWFfJiCRrXDhnuIx_lqx.md b/roadmaps/php/content/password-hashing@JbWFfJiCRrXDhnuIx_lqx.md index 9e234f733..7fb1868a1 100644 --- a/roadmaps/php/content/password-hashing@JbWFfJiCRrXDhnuIx_lqx.md +++ b/roadmaps/php/content/password-hashing@JbWFfJiCRrXDhnuIx_lqx.md @@ -1,16 +1,6 @@ # Password Hashing - -Password Hashing in PHP is a crucial aspect of security, which involves converting a plaintext password into a unique hash that cannot be easily reversed. PHP's built-in functions - `password_hash()` and `password_verify()` - are usually employed for this purpose. `password_hash()` creates a new password hash using a strong one-way hashing algorithm, while `password_verify()` checks if the given hash matches the password provided. This makes it extremely difficult for malicious actors to get the original password, even if they have the hash. - - // Hashing the password - $hash = password_hash('mypassword', PASSWORD_DEFAULT); - - // Verifying the password - if (password_verify('mypassword', $hash)) { - echo 'Password is valid!'; - } else { - echo 'Invalid password.'; - } + +PHP provides `password_hash()` to securely hash passwords using bcrypt or Argon2. The resulting hash includes the algorithm, cost factor, and salt, so no separate salt storage is needed. `password_verify()` checks a plaintext password against a stored hash. Using MD5 or SHA1 for passwords is insecure and should be avoided. Visit the following resources to learn more: diff --git a/roadmaps/php/content/pdo@cJtPz1RMN1qDE4eRdv4N_.md b/roadmaps/php/content/pdo@cJtPz1RMN1qDE4eRdv4N_.md index 5dd92b3d0..5d2466aa9 100644 --- a/roadmaps/php/content/pdo@cJtPz1RMN1qDE4eRdv4N_.md +++ b/roadmaps/php/content/pdo@cJtPz1RMN1qDE4eRdv4N_.md @@ -1,16 +1,6 @@ -# PDO - -PDO (PHP Data Objects) is an interface in PHP that provides a lightweight, consistent way for working with databases in PHP. PDO allows you to use any database without changing your PHP code, making your code database-independent. Furthermore, it offers robust error handling and can utilize prepared statements to prevent SQL injection attacks. Here is how you could connect and fetch data from a MySQL database using PDO: - - try { - $pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password'); - $stmt = $pdo->query('SELECT * FROM myTable'); - while ($row = $stmt->fetch()) { - echo $row['name'] . "\n"; - } - } catch (PDOException $e) { - echo "Connection failed: " . $e->getMessage(); - } +# Database Connectivity > PDO + +PDO (PHP Data Objects) is a database abstraction layer that provides a consistent interface for connecting to multiple database types, including MySQL, PostgreSQL, and SQLite. It supports prepared statements, which protect against SQL injection. PDO uses a DSN string to specify the driver and connection parameters. Visit the following resources to learn more: diff --git a/roadmaps/php/content/performance-optimization@M1nVsh_sCSFJRf6-7Ttsj.md b/roadmaps/php/content/performance-optimization@M1nVsh_sCSFJRf6-7Ttsj.md index 23de59739..59f04d6d8 100644 --- a/roadmaps/php/content/performance-optimization@M1nVsh_sCSFJRf6-7Ttsj.md +++ b/roadmaps/php/content/performance-optimization@M1nVsh_sCSFJRf6-7Ttsj.md @@ -1,22 +1,6 @@ # Performance Optimization - -Performance Optimization linked with Advanced Database Techniques in PHP ensures your database-driven applications run efficiently. This involves techniques like indexing, using EXPLAIN SQL command, de-normalization, and caching query results. For instance, an effective technique is caching query results, which can significantly reduce the number of database calls. PHP offers functions to serialize and unserialize data, you can store your result set in a serialized form and when needed, retrieve it quickly, unserialize it and voila, you have your data ready with no database calls. - -Here's a simple example of caching MySQL query with PHP: - - $query = "SELECT * FROM my_table"; - $cache_file = '/tmp/cache/' . md5($query); - - if (file_exists($cache_file)) { - $result_set = unserialize(file_get_contents($cache_file)); - } else { - $result= mysql_query($query); - $result_set= array(); - while ($row = mysql_fetch_array($result)) { - $result_set[]= $row; - } - file_put_contents($cache_file, serialize($result_set)); - } + +PHP performance optimization focuses on reducing response time and server load. Common approaches include using opcode caching with OPcache, reducing database queries, leveraging HTTP caching, profiling with Xdebug or Blackfire, and writing efficient loops and data structures. Application-level caching with Redis or Memcached can significantly reduce repeated computation. Visit the following resources to learn more: diff --git a/roadmaps/php/content/pest@d6MydchA52HIxfAUjmZui.md b/roadmaps/php/content/pest@d6MydchA52HIxfAUjmZui.md index 07d73d0ac..36ac43c76 100644 --- a/roadmaps/php/content/pest@d6MydchA52HIxfAUjmZui.md +++ b/roadmaps/php/content/pest@d6MydchA52HIxfAUjmZui.md @@ -1,11 +1,6 @@ # Pest - -Pest is an innovative and elegant testing framework for PHP. Think of it as a stylish and streamlined alternative to PHPUnit. Pest makes testing your PHP code a breeze by enabling expressive and flexible test cases. It provides higher-level abstractions to minimize boilerplate code without disrupting the ability to integrate traditional PHPUnit tests. For example, using Pest can make a test case as simple as writing a closure: - - it('has homepage', function () { - $response = get('/'); - $response->assertStatus(200); - }); + +Pest is a modern PHP testing framework built on top of PHPUnit. It offers a more expressive, function-based syntax that reduces boilerplate and improves readability. Pest supports all PHPUnit features while adding its own: higher-order tests, parallel execution, and architecture testing. It is popular in Laravel communities. Visit the following resources to learn more: diff --git a/roadmaps/php/content/php-cs-fixer@r07k_hT2z2EiIBH4q3F7-.md b/roadmaps/php/content/php-cs-fixer@r07k_hT2z2EiIBH4q3F7-.md index c19d26c3b..3a15d9428 100644 --- a/roadmaps/php/content/php-cs-fixer@r07k_hT2z2EiIBH4q3F7-.md +++ b/roadmaps/php/content/php-cs-fixer@r07k_hT2z2EiIBH4q3F7-.md @@ -1,13 +1,6 @@ # PHP CS Fixer - -PHP CS Fixer is a valuable utility for PHP developers that examines and fixes your code to ensure it aligns with specific coding standards. This powerful tool diminishes the time and effort spent on manual code review and corrections. It reviews your PHP code's syntax, appearance, and structure and can automatically fix issues found. PHP CS Fixer supports PSR-1, PSR-2, Symfony standards, and more. Here's an example of how you can use PHP CS Fixer. First, install it via composer: - - composer global require friendsofphp/php-cs-fixer - - -Then, run this command in your project directory: - - php-cs-fixer fix /path-to-your-php-files + +PHP CS Fixer automatically reformats PHP code to comply with coding standards. It supports PSR standards and allows custom rule configurations. Unlike PHP_CodeSniffer, its primary mode is fixing rather than reporting. It is configured via a `.php-cs-fixer.php` file and integrates with editor plugins and CI workflows. Visit the following resources to learn more: diff --git a/roadmaps/php/content/php-fpm@AoGS-5MSkp8gtJFQVPSBE.md b/roadmaps/php/content/php-fpm@AoGS-5MSkp8gtJFQVPSBE.md index 7469edeae..8f43ddbca 100644 --- a/roadmaps/php/content/php-fpm@AoGS-5MSkp8gtJFQVPSBE.md +++ b/roadmaps/php/content/php-fpm@AoGS-5MSkp8gtJFQVPSBE.md @@ -1,17 +1,6 @@ # PHP-FPM - -PHP-FPM, or PHP FastCGI Process Manager, is a robust and efficient way to serve PHP applications. It dramatically improves the speed and processing efficiency of PHP apps by isolating each request, thus preventing jobs from interfering with each other. With PHP-FPM, your server can handle more simultaneous visitors without a slowdown. For example, to start using PHP-FPM with NGINX, you may include this configuration in your NGINX server block: - - location ~ \.php$ { - try_files $uri =404; - fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - include fastcgi_params; - } - - -Here `$uri` is the incoming request and `fastcgi_pass` should be the location where PHP-FPM listens. + +PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation designed for high-traffic sites. It manages a pool of worker processes that handle incoming requests, supports dynamic and static process scaling, and can be configured with per-pool settings. PHP-FPM pairs with Nginx or Apache using the FastCGI protocol. Visit the following resources to learn more: diff --git a/roadmaps/php/content/phpstan@12k71gNfwAcT9K5aLWgbZ.md b/roadmaps/php/content/phpstan@12k71gNfwAcT9K5aLWgbZ.md index 819d4391c..15e048dad 100644 --- a/roadmaps/php/content/phpstan@12k71gNfwAcT9K5aLWgbZ.md +++ b/roadmaps/php/content/phpstan@12k71gNfwAcT9K5aLWgbZ.md @@ -1,14 +1,6 @@ # PHPStan - -PHPStan is a static analysis tool for PHP that focuses on discovering bugs in your code. As opposed to dynamic analysis which works while your program is running, static analysis examines your code without executing it. PHPStan can catch an entire class of bugs even before you write tests for the code, thus making it a valuable tool in PHP development. For example, PHPStan can prevent issues like accessing an undefined array key or calling a method that doesn't exist. - -Here's a basic example of how you can use PHPStan: - - // install PHPStan using composer - $ composer require --dev phpstan/phpstan - - // analyse your code - $ vendor/bin/phpstan analyse src + +PHPStan is a static analysis tool for PHP that finds bugs by analyzing types and logic without running the code. It operates on configurable strictness levels (0–9), with higher levels catching more issues. PHPStan understands PHPDoc annotations and can be extended with custom rules for framework-specific patterns. Visit the following resources to learn more: diff --git a/roadmaps/php/content/phpunit@NfBKKwG2GGBPppOjoLLBg.md b/roadmaps/php/content/phpunit@NfBKKwG2GGBPppOjoLLBg.md index 81640aa20..b325332da 100644 --- a/roadmaps/php/content/phpunit@NfBKKwG2GGBPppOjoLLBg.md +++ b/roadmaps/php/content/phpunit@NfBKKwG2GGBPppOjoLLBg.md @@ -1,29 +1,6 @@ # PHPUnit - -PHPUnit is a widely used testing framework in PHP. Automated testing allows developers to ensure their code functions as expected. With PHPUnit, you can write test cases in PHP to check the functionality of your codebase. It's particularly good for executing unit tests - tests that verify individual parts of the software. PHPUnit supports several types of assertions, making it versatile for any testing requirement. Here's a simple PHPUnit test case: - - assertEquals(0, count($stack)); - - array_push($stack, 'foo'); - $this->assertEquals('foo', $stack[count($stack)-1]); - $this->assertEquals(1, count($stack)); - - $this->assertEquals('foo', array_pop($stack)); - $this->assertEquals(0, count($stack)); - } - } - ?> - - -In this example, we’re testing the 'push' and 'pop' functionality of an array. + +PHPUnit is the de facto testing framework for PHP. It supports unit tests, integration tests, and test doubles (mocks, stubs, fakes). Test classes extend `PHPUnit\Framework\TestCase` and use assertion methods like `assertEquals()` and `assertNull()`. PHPUnit integrates with CI pipelines and code coverage tools. Visit the following resources to learn more: diff --git a/roadmaps/php/content/polymorphism@gtq5KrghF28f5G8nuDcYQ.md b/roadmaps/php/content/polymorphism@gtq5KrghF28f5G8nuDcYQ.md index 010ce9882..9dc389935 100644 --- a/roadmaps/php/content/polymorphism@gtq5KrghF28f5G8nuDcYQ.md +++ b/roadmaps/php/content/polymorphism@gtq5KrghF28f5G8nuDcYQ.md @@ -1,36 +1,6 @@ # Polymorphism - -Polymorphism is a core concept in object-oriented programming that PHP supports. It provides a mechanism to use one interface for different underlying forms, enabling different objects to process differently based on their data type. In PHP, polymorphism can be achieved through inheritance and interfaces. For example, you may have a parent class 'Shape' and child classes 'Circle', 'Rectangle', etc. They all can have a method 'draw' but with different implementations. It's not limited to classes; you can also use polymorphism with interfaces by implementing different classes with the same interface where each class will have different code for the same method. - -Here's a small sample code demonstrating the concept: - - draw(); - } - - drawShape(new Circle()); - drawShape(new Rectangle()); - ?> - - -This creates a scalable way to add more shapes, as you only need to follow the 'Shape' interface. + +Polymorphism allows different classes to be used through a common interface while each provides its own implementation. In PHP, this is achieved through method overriding and interface implementation. Code that depends on an interface or abstract type can work with any concrete class that satisfies it. Visit the following resources to learn more: diff --git a/roadmaps/php/content/process-control@NTKUMgsKGYISIyhgOJPQn.md b/roadmaps/php/content/process-control@NTKUMgsKGYISIyhgOJPQn.md index aa97f4bf9..5a807f7b8 100644 --- a/roadmaps/php/content/process-control@NTKUMgsKGYISIyhgOJPQn.md +++ b/roadmaps/php/content/process-control@NTKUMgsKGYISIyhgOJPQn.md @@ -1,20 +1,6 @@ # Process Control - -Process Control, a crucial aspect of PHP system interactions, pertains to the ability to manage child processes within larger PHP scripts. Through the Process Control Extensions, PHP can create, monitor and control these child processes efficiently. These functions help develop robust client-server systems by managing and bringing multi-threading capabilities to single-threaded PHP scripts. For instance, when creating a new child process using pcntl\_fork() function, the return value in the parent process is the PID of the newly created child process whereas, in the child process, '0' is returned. Remember, this feature isn't enabled by default in PHP. - -Here's a short PHP code demonstrating Process Control: - - + +PHP can manage processes using the PCNTL extension, which provides functions for forking, signaling, and waiting on child processes. Process control is used in CLI scripts and long-running daemons. Signal handling with `pcntl_signal()` allows graceful shutdown or custom responses to OS signals like SIGTERM. Visit the following resources to learn more: diff --git a/roadmaps/php/content/profiling-techniques@_Dh78x_tPLqZweg--qZFQ.md b/roadmaps/php/content/profiling-techniques@_Dh78x_tPLqZweg--qZFQ.md index c52813fa6..ef332de7d 100644 --- a/roadmaps/php/content/profiling-techniques@_Dh78x_tPLqZweg--qZFQ.md +++ b/roadmaps/php/content/profiling-techniques@_Dh78x_tPLqZweg--qZFQ.md @@ -1,10 +1,6 @@ # Profiling Techniques - -Profiling is an analytical process within PHP that focuses on optimizing the application’s performance. It involves pinpointing bottlenecks and problematic sections of your PHP code that cause poor performance, often using profiling tools. One such tool is Xdebug, which provides detailed information about how each line of code is executed. This process helps in understanding how long an operation takes to execute, which parts consume more memory, and which functions/methods are most frequently used, thereby enabling an optimization strategy. Here's a snippet of how to use Xdebug: - - xdebug_start_trace(); - // Your code here - xdebug_stop_trace(); + +Profiling identifies which parts of a PHP application consume the most time or memory. Xdebug's profiler generates cachegrind files visualized with tools like KCachegrind. Blackfire.io provides detailed call graphs and timeline views without the overhead of Xdebug in production. Tideways is another option for continuous profiling. Visit the following resources to learn more: diff --git a/roadmaps/php/content/properties-and-methods@MRAPXshy9RoYdReY6grf_.md b/roadmaps/php/content/properties-and-methods@MRAPXshy9RoYdReY6grf_.md index e268eb3cc..497d501a2 100644 --- a/roadmaps/php/content/properties-and-methods@MRAPXshy9RoYdReY6grf_.md +++ b/roadmaps/php/content/properties-and-methods@MRAPXshy9RoYdReY6grf_.md @@ -1,20 +1,6 @@ # Properties and Methods - -Properties and Methods are fundamental components of Object-Oriented Programming (OOP) in PHP. Properties are just like variables; they hold information that an object will need to use. Methods, on the other hand, are similar to functions; they perform an action on an object's properties. In PHP, properties are declared using visibility keywords (public, protected, or private) followed by a regular variable declaration, while methods are declared like functions but inside a class. - -Here is a simple example: - - class Car { - public $color; // Property - - // Method - public function setColor($color) { - $this->color = $color; - } - } - - -In this example, `$color` is a property and `setColor()` is a method. + +Properties are variables defined within a class that hold an object's state. Methods are functions defined within a class that define its behavior. Both can be `public`, `protected`, or `private`, controlling their visibility. PHP 8 introduced promoted constructor properties to reduce boilerplate. Visit the following resources to learn more: diff --git a/roadmaps/php/content/psalm@T1XD93j6Lkpl88JSmys9b.md b/roadmaps/php/content/psalm@T1XD93j6Lkpl88JSmys9b.md index 0ac3be68a..d1d7576c9 100644 --- a/roadmaps/php/content/psalm@T1XD93j6Lkpl88JSmys9b.md +++ b/roadmaps/php/content/psalm@T1XD93j6Lkpl88JSmys9b.md @@ -1,10 +1,6 @@ # Psalm - -Psalm is a popular static analysis tool tailored for PHP. It identifies potential issues in your code, including syntax errors, unused variables, and type mismatches, before you run the code. This helps to improve code quality and maintainability. It's quite powerful, it can even understand complex scenarios using its template/interface system. To analyze your PHP code with Psalm, you simply need to install it and then run it against your PHP file or directory. - -Here's an example of how you might run Psalm against a file called 'example.php': - - vendor/bin/psalm example.php + +Psalm is a static analysis tool developed by Vimeo that focuses on type safety in PHP. It uses PHPDoc annotations and native type hints to infer and check types across the codebase. Psalm supports a security analysis mode that tracks tainted user input through the code to detect potential vulnerabilities. Visit the following resources to learn more: diff --git a/roadmaps/php/content/psr-standards@3tONibbRgK7HCwGTE2Gqw.md b/roadmaps/php/content/psr-standards@3tONibbRgK7HCwGTE2Gqw.md index 7c7227ffe..15e8343ec 100644 --- a/roadmaps/php/content/psr-standards@3tONibbRgK7HCwGTE2Gqw.md +++ b/roadmaps/php/content/psr-standards@3tONibbRgK7HCwGTE2Gqw.md @@ -1,19 +1,6 @@ # PSR Standards - -The PHP Framework Interop Group (PHP-FIG) introduced PHP Standard Recommendation (PSR) standards to provide a uniform and interoperable set of coding practices for PHP developers. PSR standards cover a variety of coding aspects such as code style (PSR-1, PSR-2), autoloading (PSR-4), and more. The PHP community widely accepts these standards contributing towards writing clean and easy-to-follow code. - -Here's a snippet to illustrate the PSR-4 autoloading standards in PHP: - - // Register the autoloader - spl_autoload_register(function ($class) { - // Convert namespace to directory structure - $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; - - // Get file if it exists - if (file_exists($class)) { - require $class; - } - }); + +PSR (PHP Standard Recommendations) are specifications published by PHP-FIG that define common interfaces and conventions for PHP projects. Key PSRs include PSR-4 (autoloading), PSR-7 (HTTP message interfaces), PSR-12 (coding style), and PSR-3 (logging interface). Adhering to PSR standards makes libraries easier to integrate and swap. Visit the following resources to learn more: diff --git a/roadmaps/php/content/reading-files@S9wTlkbv9-R6dohhZ47hs.md b/roadmaps/php/content/reading-files@S9wTlkbv9-R6dohhZ47hs.md index 5a1f969ce..49214cc9e 100644 --- a/roadmaps/php/content/reading-files@S9wTlkbv9-R6dohhZ47hs.md +++ b/roadmaps/php/content/reading-files@S9wTlkbv9-R6dohhZ47hs.md @@ -1,18 +1,6 @@ # Reading Files - -Reading files is a common task in PHP and it provides a range of functions for this purpose. You can use the `fopen()` function with the 'r' mode to open a file for reading. The `fgets()` function lets you read a file line by line, while `fread()` reads a specified number of bytes. For reading the entire file in one go, use `file_get_contents()`. Remember to always close the file after you're done with `fclose()`. - -Here's a small example using `fgets()`: - - $file = fopen("example.txt", "r"); - if ($file) { - while (($line = fgets($file)) !== false) { - echo $line; - } - fclose($file); - } else { - echo 'Error opening file'; - } + +PHP reads file contents using functions like `file_get_contents()` for reading the entire file as a string, and `fopen()` with `fread()` for reading in chunks. `file()` reads a file into an array of lines. File reading is used for logs, configuration files, uploads, and data imports. Visit the following resources to learn more: diff --git a/roadmaps/php/content/recursion@D9ybK5INH5zSOcYMb5ZPi.md b/roadmaps/php/content/recursion@D9ybK5INH5zSOcYMb5ZPi.md index 040bb66eb..123218d7a 100644 --- a/roadmaps/php/content/recursion@D9ybK5INH5zSOcYMb5ZPi.md +++ b/roadmaps/php/content/recursion@D9ybK5INH5zSOcYMb5ZPi.md @@ -1,17 +1,6 @@ # Recursion - -Recursion, as it applies to PHP, refers to a function that calls itself to solve a problem. A recursive function distinguishes itself by solving small parts of the problem until it resolves the main issue. Think of it as breaking down a task into smaller tasks that are easier to solve. However, careful design is needed to ensure the recursive function has a clear stopping point, or else it can result in an infinite loop. Here's a quick example of a simple recursive function in PHP: - - function countDown($count) { - echo $count; - if($count > 0) { - countDown($count - 1); - } - } - countDown(5); - - -In this example, the function `countDown` calls itself until the count hits zero, displaying numbers from 5 to 0. + +Recursion is a technique where a function calls itself to solve a smaller version of the same problem. Each recursive call must move toward a base case that stops the recursion. PHP supports recursion but does not optimize tail calls, so deep recursion can exhaust the call stack. Visit the following resources to learn more: diff --git a/roadmaps/php/content/require@Kaaqu-mN7xvHN6CbIn616.md b/roadmaps/php/content/require@Kaaqu-mN7xvHN6CbIn616.md index 5b4d7edc3..3406d51b0 100644 --- a/roadmaps/php/content/require@Kaaqu-mN7xvHN6CbIn616.md +++ b/roadmaps/php/content/require@Kaaqu-mN7xvHN6CbIn616.md @@ -1,6 +1,6 @@ # require - -The 'require' statement is a built-in feature of PHP used to include and evaluate a specific file while executing the code. This is a crucial part of file handling in PHP because it enables the sharing of functions, classes, or elements across multiple scripts, promoting code reusability and neatness. Keep in mind, if the required file is missing, PHP will produce a fatal error and stop the code execution. The basic syntax is `require 'filename';`. + +`require` includes and evaluates a specified PHP file. If the file is not found, PHP throws a fatal error and halts execution. It is used when the included file is mandatory for the script to run, such as a configuration file or a class definition. Visit the following resources to learn more: diff --git a/roadmaps/php/content/require_once@-CyJbsg2ho3RvfzKnJj5C.md b/roadmaps/php/content/require_once@-CyJbsg2ho3RvfzKnJj5C.md index 417f71768..b08f923c1 100644 --- a/roadmaps/php/content/require_once@-CyJbsg2ho3RvfzKnJj5C.md +++ b/roadmaps/php/content/require_once@-CyJbsg2ho3RvfzKnJj5C.md @@ -1,15 +1,6 @@ # require_once - -PHP uses the 'require\_once' statement as an efficient way to include a PHP file into another one. There's an interesting quirk to this function: PHP checks if the file was previously included, and if so, it doesn't include the file again. This helps avoid problems with redundant function declarations, variable value reassignments, or coding loops. However, do remember that 'require\_once' is distinct from 'include\_once'. The key difference lies in error handling: if the file specified in 'require\_once' cannot be found, PHP will emit a fatal error and halt script execution. Whereas, 'include\_once', will only generate a warning. - -Here's how you can utilize 'require\_once': - - - - -This code fetches all the functions and codes from 'somefile.php' and includes them in the current file. + +`require_once` works like `require` but checks whether the file has already been included and skips it if so. This prevents duplicate declarations of classes, functions, or constants when the same file might be included from multiple places. It is commonly used in class autoloading and bootstrap files. Visit the following resources to learn more: diff --git a/roadmaps/php/content/sanitization-techniques@tfC1tCrbvH5J43WUpG9Yb.md b/roadmaps/php/content/sanitization-techniques@tfC1tCrbvH5J43WUpG9Yb.md index 2cffcc106..632a241d7 100644 --- a/roadmaps/php/content/sanitization-techniques@tfC1tCrbvH5J43WUpG9Yb.md +++ b/roadmaps/php/content/sanitization-techniques@tfC1tCrbvH5J43WUpG9Yb.md @@ -1,10 +1,6 @@ # Sanitization Techniques - -Sanitization Techniques is a vital part of PHP security basics, which ensures that the user-provided data is safe to be used within your script. It can prevent harmful data from being inserted into the database or being used in other ways that could potentially be dangerous to your application. It includes functions which can strip off unwanted characters from the data. For instance, the `filter_var()` function in PHP can be applied to sanitize text. - - $dirty_data = "We love PHP!
"; - $clean_data = filter_var($dirty_data, FILTER_SANITIZE_STRING); - echo $clean_data; + +Sanitization removes or encodes unsafe characters from user input before using it in output, queries, or commands. PHP provides `htmlspecialchars()` to escape HTML, `strip_tags()` to remove HTML tags, and `filter_var()` with filters like `FILTER_SANITIZE_EMAIL`. Sanitization reduces the risk of XSS and injection attacks. Visit the following resources to learn more: diff --git a/roadmaps/php/content/sessions@qobzzgzArNHLLn9Oiqc6G.md b/roadmaps/php/content/sessions@qobzzgzArNHLLn9Oiqc6G.md index 2cbe745e5..d84bd016a 100644 --- a/roadmaps/php/content/sessions@qobzzgzArNHLLn9Oiqc6G.md +++ b/roadmaps/php/content/sessions@qobzzgzArNHLLn9Oiqc6G.md @@ -1,6 +1,6 @@ # Sessions -Sessions provide a way to preserve certain data across subsequent accesses. Unlike a cookie, the information is not stored on the user's computer but on the server. This is particularly useful when you want to store information related to a specific user's session on your platform, like user login status or user preferences. When a session is started in PHP, a unique session ID is generated for the user. This ID is then passed and tracked through a cookie in the user's browser. To start a session, you would use the PHP function session\_start(). To save a value in a session, you'd use the $\_SESSION superglobal array. For example, `$_SESSION['username'] = 'John';` assigns 'John' to the session variable 'username'. +Sessions store user data on the server across multiple requests. A session is started with `session_start()`, and data is stored in the `$_SESSION` superglobal. PHP sends the session ID to the client as a cookie by default. Sessions expire when the browser closes or after a configurable timeout. Visit the following resources to learn more: diff --git a/roadmaps/php/content/sql-injection@801vB_JMas4ucriUmfrLg.md b/roadmaps/php/content/sql-injection@801vB_JMas4ucriUmfrLg.md index d9256d3dc..af43216c8 100644 --- a/roadmaps/php/content/sql-injection@801vB_JMas4ucriUmfrLg.md +++ b/roadmaps/php/content/sql-injection@801vB_JMas4ucriUmfrLg.md @@ -1,6 +1,6 @@ # SQL Injection - -SQL Injection is a crucial security topic in PHP. It is a code injection technique where an attacker may slip shady SQL code within a query. This attack can lead to data manipulation or loss and even compromise your database. To prevent this, PHP encourages the use of prepared statements with either the MySQLi or PDO extension. An example of a vulnerable code snippet would be: `$unsafe_variable = $_POST['user_input']; mysqli_query($link, "INSERT INTO` table `(`column`) VALUES ('$unsafe_variable')");`. Stop falling prey to injections by utilizing prepared statement like so: `$stmt = $pdo->prepare('INSERT INTO` table `(`column`) VALUES (?)'); $stmt->execute([$safe_variable]);`. + +SQL injection occurs when unvalidated user input is interpolated directly into a SQL query, allowing attackers to manipulate the query. The fix is to use prepared statements with parameterized queries through PDO or MySQLi. Never construct SQL strings by concatenating user input directly. Visit the following resources to learn more: diff --git a/roadmaps/php/content/state-management@CGehmZjcgTWC7fQAvxmNW.md b/roadmaps/php/content/state-management@CGehmZjcgTWC7fQAvxmNW.md index 585e682b2..0e4baef5e 100644 --- a/roadmaps/php/content/state-management@CGehmZjcgTWC7fQAvxmNW.md +++ b/roadmaps/php/content/state-management@CGehmZjcgTWC7fQAvxmNW.md @@ -1,6 +1,6 @@ # State Management -State management in PHP involves keeping track of user activity in the application, as HTTP protocol doesn't store earlier interactions. Typically, these data involve user details such as login info, form input data, etc. A prevalent method of state management in PHP is through sessions and cookies. Sessions work by keeping the state data on the server side and a session identifier on the client side. Note, session's info remains active until the user's session expires. On the other hand, cookies store data on the client side, having an expiry date or until the user deletes them. Here's how to set a cookie in PHP: `setcookie("test_cookie", "test", time() + 3600, '/');`. To access sessions, use the `_SESSION` superglobal array: `$_SESSION["favcolor"] = "green";`. +HTTP is stateless, so PHP uses sessions and cookies to maintain state between requests. Sessions store data on the server and identify the user with a session ID sent in a cookie. Cookies store small pieces of data directly in the browser. Together they enable features like login persistence, shopping carts, and user preferences. Visit the following resources to learn more: diff --git a/roadmaps/php/content/static-analysis@PrG_5dyBblXsWYYRcOJMa.md b/roadmaps/php/content/static-analysis@PrG_5dyBblXsWYYRcOJMa.md index bed83427e..5894531f2 100644 --- a/roadmaps/php/content/static-analysis@PrG_5dyBblXsWYYRcOJMa.md +++ b/roadmaps/php/content/static-analysis@PrG_5dyBblXsWYYRcOJMa.md @@ -1,12 +1,6 @@ # Static Analysis - -Static analysis in PHP is a method to inspect the source code before running it. Rather than testing programs on specific inputs (dynamic analysis), static analysis focuses on finding potential issues within code without executing it. It can help in identifying common coding mistakes and uncovering complex problems like dependency issues, unused variables, undeclared properties, and more. Using tools such as PHPStan or Psalm provides this static analysis feature in PHP. For instance, using PHPStan involves merely installing it via Composer and running it against your codebase. - - composer require --dev phpstan/phpstan - ./vendor/bin/phpstan analyse src - - -It outputs information about any issues it finds in code. However, to reap the full benefits, understand that these tools require proper configuration and regular usage. + +Static analysis examines PHP code for errors, type inconsistencies, and potential bugs without executing it. Tools analyze the codebase and report issues like undefined variables, incorrect method calls, or type mismatches. Static analysis catches bugs early in development and improves code quality over time. Visit the following resources to learn more: diff --git a/roadmaps/php/content/static-methods-and-properties@qlkpwXfOc1p7j37hrzffI.md b/roadmaps/php/content/static-methods-and-properties@qlkpwXfOc1p7j37hrzffI.md index 48f856d2e..d1ff6ecbc 100644 --- a/roadmaps/php/content/static-methods-and-properties@qlkpwXfOc1p7j37hrzffI.md +++ b/roadmaps/php/content/static-methods-and-properties@qlkpwXfOc1p7j37hrzffI.md @@ -1,19 +1,6 @@ # Static Methods and Properties - -Static methods and properties in PHP belong to the class rather than an instance of the class. This means they can be accessed without creating an object of the class. A static method is declared with the static keyword and can be invoked directly using the class name followed by the scope resolution operator. Similarly, a static property is also defined with the static keyword, but cannot be accessed directly, even from within the class methods - they must be accessed through static methods. Here's a simple example: - - class MyClass { - static $myStaticProperty = "Hello, world"; - - static function myStaticMethod() { - return self::$myStaticProperty; - } - } - - echo MyClass::myStaticMethod(); - - -In this example, we're directly accessing `myStaticMethod` from `MyClass` without an instantiation. + +Static members belong to the class itself rather than to any instance. They are declared with the `static` keyword and accessed using `ClassName::method()` or `self::`. Static properties retain their value across all instances. Static methods are commonly used for utility functions and factory patterns. Visit the following resources to learn more: diff --git a/roadmaps/php/content/switch@bgJ9-m6Fiu3VCc-NZlbpn.md b/roadmaps/php/content/switch@bgJ9-m6Fiu3VCc-NZlbpn.md index 2b4870e1e..521300d1b 100644 --- a/roadmaps/php/content/switch@bgJ9-m6Fiu3VCc-NZlbpn.md +++ b/roadmaps/php/content/switch@bgJ9-m6Fiu3VCc-NZlbpn.md @@ -1,24 +1,6 @@ # switch - -The switch statement is a special conditional statement in PHP that can simplify code and improve readability when you need to compare one value with multiple different possibilities. It is an alternative to using a chain of "if...else" conditions, and is particularly useful when you have many different cases to compare. The switch expression is evaluated only once, and its value is compared to each case. When a match is found, PHP executes the associated code block. - -Here's a basic switch statement: - - $fruit = "apple"; - switch ($fruit) { - case "apple": - echo "You chose apple."; - break; - case "banana": - echo "You chose banana."; - break; - default: - echo "Invalid choice."; - } - // Outputs: You chose apple. - - -Switch statements can make your code cleaner and easier to manage, especially when dealing with multiple conditions. + +The `switch` statement compares a single expression against multiple possible values using `case` labels. PHP uses loose comparison (`==`) in switch cases. Each case should end with `break` to prevent fall-through into the next case. `default` handles any value not matched by a case. Visit the following resources to learn more: diff --git a/roadmaps/php/content/symfony@57VSMVePOr9qUD5x_LNdf.md b/roadmaps/php/content/symfony@57VSMVePOr9qUD5x_LNdf.md index 8d6b7680e..9eaf145ff 100644 --- a/roadmaps/php/content/symfony@57VSMVePOr9qUD5x_LNdf.md +++ b/roadmaps/php/content/symfony@57VSMVePOr9qUD5x_LNdf.md @@ -1,11 +1,6 @@ # Symfony - -Symfony is a set of PHP components and a framework for web projects. It aims to speed up the creation and maintenance of web applications and replace the recurring coding tasks. Symfony uses Composer, a PHP dependency manager, to manage its components. Below is an example of creating a new Symfony project: - - composer create-project symfony/website-skeleton myproject - - -This will download and install a new Symfony project in the 'myproject' directory. Symfony's components are reusable PHP libraries that will help you complete tasks, like routing, templating, or even creating form handling. + +Symfony is a mature PHP framework and a collection of reusable components. It follows MVC conventions and emphasizes flexibility through dependency injection, event dispatchers, and a powerful routing and templating system (Twig). Many other PHP projects and frameworks, including Drupal and API Platform, are built on Symfony components. Visit the following resources to learn more: diff --git a/roadmaps/php/content/traits@GR09ns9B-0cONQaQ_uj-7.md b/roadmaps/php/content/traits@GR09ns9B-0cONQaQ_uj-7.md index c87a4596a..322000c9c 100644 --- a/roadmaps/php/content/traits@GR09ns9B-0cONQaQ_uj-7.md +++ b/roadmaps/php/content/traits@GR09ns9B-0cONQaQ_uj-7.md @@ -1,22 +1,6 @@ # Traits - -Traits is a concept in PHP that allows code reusability by enabling developers to create reusable pieces of code which can be used in classes to extend functionality. They are a way to reduce intricacies of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes. - -Here's an example how to use a Trait: - - trait Greeting { - public function sayHello() { - return "Hello"; - } - } - class User { - use Greeting; - } - $user = new User(); - echo $user->sayHello(); // Outputs: Hello - - -In the above code snippet, the `Greeting` trait is being used in the `User` class, and we are able to use its methods as if they were defined in the `User` class. + +Traits are a mechanism for code reuse in single-inheritance languages like PHP. A trait defines methods that can be inserted into any class using the `use` keyword. A class can use multiple traits simultaneously. Traits are useful for sharing behavior across classes that don't share a common parent. Visit the following resources to learn more: diff --git a/roadmaps/php/content/type-declarations@sPW-Ti2VyNYzxq6EYkbn7.md b/roadmaps/php/content/type-declarations@sPW-Ti2VyNYzxq6EYkbn7.md index 447da3162..190bbc17a 100644 --- a/roadmaps/php/content/type-declarations@sPW-Ti2VyNYzxq6EYkbn7.md +++ b/roadmaps/php/content/type-declarations@sPW-Ti2VyNYzxq6EYkbn7.md @@ -1,17 +1,6 @@ # Type Declarations - -Type declarations, also known as type hints, are a feature in PHP that provides you options to specify the type of variable that a function is expected to receive or the type of value that it should return. Not only does it help to debug code quickly, it also makes the code more readable. In PHP, type declarations can be for both parameters in a function (parameter type declarations) and return values from a function (return type declarations). They can apply to classes, interfaces, callable, and scalar types (int, float, string, bool). - -Here's an example: - - function add(int $a, int $b): int { - return $a + $b; - } - - echo add(1, 2); // prints: 3 - - -In this example, the function 'add' only accepts integers and also returns an integer. + +Type declarations specify the expected types for function parameters, return values, and class properties. PHP supports scalar types (`int`, `string`, `bool`, `float`), compound types (`array`, `callable`), class types, nullable types (`?Type`), union types (`Type1|Type2`), and the `mixed` type. Strict mode enforces types without implicit coercion. Visit the following resources to learn more: diff --git a/roadmaps/php/content/var_dump@JCCeVC0hOrvIeyfg1ScKA.md b/roadmaps/php/content/var_dump@JCCeVC0hOrvIeyfg1ScKA.md index 7c1fc842f..e95a87e34 100644 --- a/roadmaps/php/content/var_dump@JCCeVC0hOrvIeyfg1ScKA.md +++ b/roadmaps/php/content/var_dump@JCCeVC0hOrvIeyfg1ScKA.md @@ -1,12 +1,6 @@ # var_dump - -Var\_dump is a built-in PHP function that's incredibly handy for debugging as it outputs the data type and value of a given variable. This includes array elements and object properties, if given such types. If you're wrangling with your PHP code and finding your variables aren't behaving as you expect, using var\_dump can quickly show you what you're working with. Check out a simple usage example below: - - $myVar = array( "Hello", "World!"); - var_dump($myVar); - - -This will output the size of array and details of each element in the array. + +`var_dump()` outputs the type and value of one or more variables. For arrays and objects, it recursively displays the structure and types of all nested values. It is primarily used during debugging to inspect what a variable actually contains. Visit the following resources to learn more: diff --git a/roadmaps/php/content/variables-and-scope@D0BtyxyjIBcpfn5wP23WC.md b/roadmaps/php/content/variables-and-scope@D0BtyxyjIBcpfn5wP23WC.md index d00f77d5b..d49cdd169 100644 --- a/roadmaps/php/content/variables-and-scope@D0BtyxyjIBcpfn5wP23WC.md +++ b/roadmaps/php/content/variables-and-scope@D0BtyxyjIBcpfn5wP23WC.md @@ -1,13 +1,6 @@ # Variables and Scope -Variables are a central part of PHP, allowing you to store data that can be used later in your scripts. Their values can be of various types including strings, integers, arrays, and objects. PHP has both local and global scope when it comes to variables. Local scope refers to variables that are only accessible within the function they are defined, while global scope means a variable is accessible to any part of the script. However, to use a global variable inside a function, you need to declare it as global. Here's a brief example: - - $x = 10; //global variable - function test() { - global $x; // accessing the global variable - echo $x; - } - test(); //prints 10 +Variables in PHP are declared with a `$` prefix and hold values of any type. Scope determines where a variable is accessible: variables defined outside a function are global and not accessible inside functions unless declared with the `global` keyword. PHP also supports static variables, which retain their value between function calls. Visit the following resources to learn more: diff --git a/roadmaps/php/content/variadic-functions@rtmytETfyyLdcXUC0QyzL.md b/roadmaps/php/content/variadic-functions@rtmytETfyyLdcXUC0QyzL.md index 70e98e734..f1cb3847c 100644 --- a/roadmaps/php/content/variadic-functions@rtmytETfyyLdcXUC0QyzL.md +++ b/roadmaps/php/content/variadic-functions@rtmytETfyyLdcXUC0QyzL.md @@ -1,16 +1,6 @@ # Variadic Functions - -Variadic functions in PHP are functions that can accept any number of arguments. This gives you greater flexibility, as it allows for an undetermined number of arguments. You can create a variadic function by adding '...' before the function argument. Any number of arguments you provide when calling the function are treated as an array, which can be processed using common array functions. - -A simple code example: - - function sum(...$numbers) { - return array_sum($numbers); - } - echo sum(1, 2, 3, 4); - - -This prints "10". The function accepts any number of arguments and adds them together. + +Variadic functions accept a variable number of arguments using the `...` spread operator in the parameter list, like `function sum(...$numbers)`. All extra arguments are collected into an array. The spread operator can also be used in function calls to unpack an array into arguments. Visit the following resources to learn more: diff --git a/roadmaps/php/content/writing-files@two4UycJaCfSp6jQqtTAb.md b/roadmaps/php/content/writing-files@two4UycJaCfSp6jQqtTAb.md index 4d58ec2e3..6227b8b97 100644 --- a/roadmaps/php/content/writing-files@two4UycJaCfSp6jQqtTAb.md +++ b/roadmaps/php/content/writing-files@two4UycJaCfSp6jQqtTAb.md @@ -1,14 +1,6 @@ # Writing Files - -Writing files plays a crucial part in PHP, allowing you to store data and modify it later. This process involves opening the file, writing the desired data, and then closing it. Writing can be done using different functions, but `fwrite()` is the most commonly used one. It requires two arguments the file pointer and the string of data to be written. Here's a brief snippet of code for instance: - - $file = 'data.txt'; - $current = file_get_contents($file); - $current .= "New Data\n"; - file_put_contents($file, $current); - - -In this code, `file_get_contents()` is used to get the current data, then new data is appended, and `file_put_contents()` is used to write back to the file. + +PHP writes to files using `file_put_contents()` for simple writes or `fopen()` with `fwrite()` for more control. The `FILE_APPEND` flag appends to an existing file instead of overwriting it. File locking with `LOCK_EX` prevents race conditions when multiple processes write concurrently. Visit the following resources to learn more: diff --git a/roadmaps/php/content/xampp@-wniKEBwbF0Fi1fHpF-Gc.md b/roadmaps/php/content/xampp@-wniKEBwbF0Fi1fHpF-Gc.md index 54a97e436..1f1e11482 100644 --- a/roadmaps/php/content/xampp@-wniKEBwbF0Fi1fHpF-Gc.md +++ b/roadmaps/php/content/xampp@-wniKEBwbF0Fi1fHpF-Gc.md @@ -1,6 +1,6 @@ # XAMPP -XAMPP is an open-source development environment that stands for Cross-Platform (X), Apache server (A), MariaDB (M), PHP (P), and Perl (P). If you're working with PHP, it's a handy tool because it creates a local web server for testing or development purposes. It's especially useful if you plan to use a database in your project, as it includes MariaDB. It integrates seamlessly with PHP, enabling you to manage your server, scripting language, and database from a unified platform with less hassle. A code sample isn't really applicable here as XAMPP is more about setup and management. For more information, you can visit the official PHP documentation: . +XAMP (Cross-Platform, Apache, MariaDB, PHP) is a lightweight local development stack. It bundles Apache, MariaDB, and PHP into a single installer, making it easy to run a web server locally without manual configuration. It is commonly used on Linux and less widely distributed than XAMPP. Visit the following resources to learn more: diff --git a/roadmaps/php/content/xdebug@lFoHoMRywCWa056ii5cKQ.md b/roadmaps/php/content/xdebug@lFoHoMRywCWa056ii5cKQ.md index 8098d6795..9f6943ebb 100644 --- a/roadmaps/php/content/xdebug@lFoHoMRywCWa056ii5cKQ.md +++ b/roadmaps/php/content/xdebug@lFoHoMRywCWa056ii5cKQ.md @@ -1,18 +1,6 @@ # Xdebug - -Xdebug is a PHP extension that provides debugging and profiling capabilities. It's a powerful tool that can help you understand what your code is doing, track down bugs, and optimize performance. With Xdebug, you can set breakpoints, watch variables, and step through your code one line at a time. For instance, to start using Xdebug, you first need to install it and then initialize it in your code like so: - - - - -Xdebug can significantly speed up bug-tracking and testing, making it an essential tool in any PHP developer's toolkit. + +Xdebug is the most widely used PHP debugging and profiling extension. It supports step debugging via the DAP protocol, integrating with editors like VS Code and PhpStorm. Xdebug also provides stack traces, code coverage analysis for use with PHPUnit, and profiling output in cachegrind format. Visit the following resources to learn more: diff --git a/roadmaps/php/content/xml-processing@ggkWo0DRSSDDkHpbiyUyf.md b/roadmaps/php/content/xml-processing@ggkWo0DRSSDDkHpbiyUyf.md index 6d86e410a..89fcc32d1 100644 --- a/roadmaps/php/content/xml-processing@ggkWo0DRSSDDkHpbiyUyf.md +++ b/roadmaps/php/content/xml-processing@ggkWo0DRSSDDkHpbiyUyf.md @@ -1,11 +1,6 @@ # XML Processing -XML processing in PHP allows manipulation and interpretation of XML documents. PHP's XML Parser extension helps to parse XML data from strings and files, providing event-driven processing capabilities. This is especially useful during large XML parsing. To process XML in PHP, you first create an XML parser, set functionality through handler functions for the start and end of elements, character data, etc., and then parse the XML data. The `xml_parser_create()`, `xml_set_element_handler()`, `xml_parse()`, and `xml_parser_free()` functions come into play here. Here's a brief snippet showing XML parsing in PHP: - - $parser = xml_parser_create(); - xml_set_element_handler($parser, "startElement", "endElement"); - xml_parse($parser, $xml_data); - xml_parser_free($parser); +PHP processes XML using two main approaches: SimpleXML for straightforward access to XML data as objects, and the DOM extension for full programmatic control over the document tree. `XMLReader` handles large XML files efficiently by streaming rather than loading the entire document into memory. Visit the following resources to learn more: diff --git a/roadmaps/php/content/xss-prevention@DxqQrToZSayWplKdCkTgT.md b/roadmaps/php/content/xss-prevention@DxqQrToZSayWplKdCkTgT.md index f3a2da416..d5c7bad7d 100644 --- a/roadmaps/php/content/xss-prevention@DxqQrToZSayWplKdCkTgT.md +++ b/roadmaps/php/content/xss-prevention@DxqQrToZSayWplKdCkTgT.md @@ -1,13 +1,6 @@ # XSS Prevention - -Cross Site Scripting, often known as XSS, is a glaring risk in web security, and PHP also must address it. It occurs when someone is able to insert dangerous code into your site, which can then be executed by users. To prevent XSS in PHP, developers should deploy `htmlspecialchars()` function to escape potentially harmful characters. This function converts special characters to their HTML entities, reducing risk. For instance, '<' becomes '<'. - -Sample PHP code to implement this: - - $secure_text = htmlspecialchars($raw_text, ENT_QUOTES, 'UTF-8'); - - -In this code, `$raw_text` contains user input that might be risky. By using `htmlspecialchars()`, `$secure_text` will now hold a sanitized version of the user input. + +Cross-Site Scripting (XSS) occurs when untrusted data is rendered in the browser as executable script. The primary defense in PHP is escaping output with `htmlspecialchars()` when rendering user-supplied content in HTML. Content Security Policy headers provide an additional layer of protection at the browser level. Visit the following resources to learn more: diff --git a/roadmaps/php/content/yii@zsscRQZIq5o0JZir9hlz-.md b/roadmaps/php/content/yii@zsscRQZIq5o0JZir9hlz-.md new file mode 100644 index 000000000..ced977a0b --- /dev/null +++ b/roadmaps/php/content/yii@zsscRQZIq5o0JZir9hlz-.md @@ -0,0 +1,8 @@ +# Yii + +Yii is a high-performance PHP framework suited for developing large-scale web applications. It uses a component-based architecture and includes built-in support for caching, authentication, RBAC, and database access via its Active Record implementation. Yii 2 is the stable release; Yii 3 is a more modular redesign. + +Visit the following resources to learn more: + +- [@official@Yii Docs](https://yiisoft.github.io/docs/) +- [@official@Demo Applications](https://yiisoft.github.io/docs/guide/start/demo-apps.html) \ No newline at end of file diff --git a/roadmaps/php/content/zend-debugger@KpQb5Zh3GUcbYUyXHvyu2.md b/roadmaps/php/content/zend-debugger@KpQb5Zh3GUcbYUyXHvyu2.md index 8e6308508..3acb587de 100644 --- a/roadmaps/php/content/zend-debugger@KpQb5Zh3GUcbYUyXHvyu2.md +++ b/roadmaps/php/content/zend-debugger@KpQb5Zh3GUcbYUyXHvyu2.md @@ -1,6 +1,6 @@ # Zend Debugger - -Zend Debugger is a PHP debugging extension used to identify issues in PHP scripts. It allows you to monitor and fix issues in your code, such as logical errors, and helps in boosting your web application's overall performance. Essentially, it becomes a simple yet powerful method for debugging server-side PHP scripts, by providing detailed debugging data and facilitating real-time interaction with the scripts. Using Zend Debugger with PHP can drastically improve the quality of your codebase and save considerable time in the development phase. A short usage example of Zend Debugger can be setting up a debug session, using the function `zend_debugger_connector_address()` which returns the IP address of the debugger currently in use. + +Zend Debugger is a PHP extension that enables remote debugging of PHP applications, typically within Zend-based development environments. It allows step-by-step execution, variable inspection, and breakpoints. It is less commonly used today compared to Xdebug but is found in enterprise setups using Zend Server. Visit the following resources to learn more: