Skip to content

Commit

Permalink
Add content to PHP roadmap (#7895)
Browse files Browse the repository at this point in the history
* Section 1

* Section 2

* Section 3

* Section 4

* Section 5
  • Loading branch information
offensive-vk authored Dec 17, 2024
1 parent 8b80f4b commit 6c099db
Show file tree
Hide file tree
Showing 119 changed files with 574 additions and 171 deletions.
6 changes: 3 additions & 3 deletions src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

$_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:

```php
```html
<form method="get" action="test.php">
Name: <input type="text" name="fname">
<input type="submit">
</form>
```

Using $_GET, you can fetch the 'fname' value from the URL:
Using $_GET in `test.php`, you can fetch the 'fname' value from the URL:

```php
echo "Name is: " . $_GET['fname'];
```

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/manual/en/reserved.variables.get.php)
- [@official@$_GET](https://www.php.net/manual/en/reserved.variables.get.php)
6 changes: 3 additions & 3 deletions src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

`$_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:

```
```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
}
?>
```

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.
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.

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/manual/en/reserved.variables.post.php)
- [@official@$_POST](https://www.php.net/manual/en/reserved.variables.post.php)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

$_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:

```
```php
$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.

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/manual/en/reserved.variables.request.php)
- [@official@$_REQUEST](https://www.php.net/manual/en/reserved.variables.request.php)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ echo 'Your IP is: ' . $_SERVER['REMOTE_ADDR'];

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/reserved.variables.server)
- [@official@$_SERVER](https://www.php.net/reserved.variables.server)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Abstract classes in PHP are those which cannot be instantiated on their own. The

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/manual/en/language.oop5.abstract.php)
- [@official@Abstract Classes](https://www.php.net/manual/en/language.oop5.abstract.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Access specifiers, also known as access modifiers, in PHP are keywords used in t

Visit the following resources to learn more:

- [@official@PHP Documentation](https://www.php.net/manual/en/language.oop5.visibility.php)
- [@official@Access Specifiers & Visibility](https://www.php.net/manual/en/language.oop5.visibility.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ In this example, we're creating an anonymous function and assigning it to the va

Visit the following resources to learn more:

- [@official@PHP Documentation - Anonymous Functions](https://www.php.net/manual/en/functions.anonymous.php)
- [@official@Anonymous Functions](https://www.php.net/manual/en/functions.anonymous.php)
4 changes: 2 additions & 2 deletions src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Apache is a popular web server that can efficiently host PHP applications. Apach

Visit the following resources to learn more:

- [@official@PHP Documentations - Apache](https://www.php.net/manual/en/install.unix.apache2.php)
- [@official@Apache Website](https://httpd.apache.org/)
- [@official@Apache PHP Documentation](https://www.php.net/manual/en/install.unix.apache2.php)
- [@official@Apache](https://httpd.apache.org/)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Arrays in PHP are fundamental data structures that store multiple elements in a

Visit the following resources to learn more:

- [@official@PHP Documentation - Arrays](https://www.php.net/manual/en/language.types.array.php)
- [@official@Arrays](https://www.php.net/manual/en/language.types.array.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Arrow functions provide a more concise syntax to create anonymous functions. The

Visit the following resources to learn more:

- [@official@PHP Documentation - Arrow Functions](https://www.php.net/manual/en/functions.arrow.php)
- [@official@Arrow Functions](https://www.php.net/manual/en/functions.arrow.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ When you are developing PHP application, security should always be a top priorit

Visit the following resources to learn more:

- [@official@PHP Documentation - Auth Mechanisms](https://www.php.net/manual/en/features.http-auth.php)
- [@official@Auth Mechanisms](https://www.php.net/manual/en/features.http-auth.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ In this example, PHP will automatically load the MyClass.php file when the MyCla

Visit the following resources to learn more:

- [@official@PHP Documentation - Autloading](https://www.php.net/manual/en/language.oop5.autoload.php)
- [@official@Autoloading](https://www.php.net/manual/en/language.oop5.autoload.php)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ PHP syntax is generally considered similar to C-style syntax, where code blocks

Visit the following resources to learn more:

- [@official@PHP Documentation - Basic Syntax](https://www.php.net/manual/en/langref.php)
- [@official@Basic Syntax](https://www.php.net/manual/en/langref.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Caching Strategies are integral to Performance Optimization in PHP. Caching mini

Visit the following resources to learn more:

- [@official@Official Documentation - Opcache](https://www.php.net/manual/en/book.opcache.php)
- [@official@Opcache](https://www.php.net/manual/en/book.opcache.php)
4 changes: 2 additions & 2 deletions src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Callback Functions

A callback function will use that function on whatever data is returned by a particular method.
A callback function in PHP is a function that is passed as an argument to another function. The receiving function can then invoke this function as needed. Callback functions are often used to define flexible or reusable code because they allow you to customize the behavior of a function without changing its structure.

Visit the following resources to learn more:

- [@official@Official Documentation - Callback functions](https://www.php.net/manual/en/language.types.callable.php)
- [@official@Callback Functions](https://www.php.net/manual/en/language.types.callable.php)
11 changes: 10 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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:

```php
<?php
$foo = 10; // $foo is an integer
$bar = (bool) $foo; // $bar is a boolean
?>
```

Visit the following resources to learn more:

- [@official@Official Documentation - Type Casting](https://www.php.net/manual/en/language.types.type-juggling.php)
- [@official@Type Casting](https://www.php.net/manual/en/language.types.type-juggling.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ PHP supports object-oriented programming, offering a multi-paradigm way of codin

Visit the following resources to learn more:

- [@official@PHP Documentation - Classes](https://www.php.net/manual/en/language.oop5.php)
- [@official@Classes](https://www.php.net/manual/en/language.oop5.php)
3 changes: 2 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ This command adds the `vendor/package` dependency to your project. The same goes

Visit the following resources to learn more:

- [@official@Composer Official Website](https://getcomposer.org/doc/)
- [@official@Composer](https://getcomposer.org/)
- [@official@Composer Documentation](https://getcomposer.org/doc/)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Conditionals in PHP, much like in other programming languages, allow for branchi

Visit the following resources to learn more:

- [@official@Official Documentation - Control Structures](https://www.php.net/manual/en/language.control-structures.php)
- [@official@Control Structures](https://www.php.net/manual/en/language.control-structures.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Configuration files are critical for PHP applications because they help manage d

Visit the following resources to learn more:

- [@official@Official Documentation - PHP Config](https://www.php.net/manual/en/ini.list.php)
- [@official@PHP Config](https://www.php.net/manual/en/ini.list.php)
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ini_set('max_execution_time', '300');

Visit the following resources to learn more:

- [@official@Official Documentation - PHP.ini](https://www.php.net/manual/en/ini.core.php)
- [@official@Configuration Tuning](https://www.php.net/manual/en/ini.core.php)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

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.

For more information, visit PHP Database Extensions [here](https://www.php.net/manual/en/refs.database.php).
Visit the following resources to learn more:

- [@official@Connection Pooling](https://www.php.net/manual/en/oci8.connection.php)
- [@official@Database Extensions](https://www.php.net/manual/en/refs.database.php)
4 changes: 3 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ define("PI", 3.14);
echo PI; // Outputs: 3.14
```

For more information, visit the PHP documentation on constants [here](https://www.php.net/manual/en/language.constants.php).
Visit the following resources to learn more:

- [@official@Constants](https://www.php.net/manual/en/language.constants.php)
4 changes: 3 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ echo $obj->value;
// And when the script ends, "Object is being destroyed."
```

Visit [PHP Constructors and Destructors](https://www.php.net/manual/en/language.oop5.decon.php) for a more detailed look at these vital concepts.
Visit the following resources to learn more:

- [@official@PHP Constructors and Destructors](https://www.php.net/manual/en/language.oop5.decon.php)
6 changes: 5 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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"];`. For more detailed information, you can visit [PHP's official documentation on cookies](https://www.php.net/manual/en/features.cookies.php).
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"];`.

Visit the following resources to learn more:

- [@official@Cookies](https://www.php.net/manual/en/features.cookies.php)
6 changes: 4 additions & 2 deletions src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.

```
```php
<?php
// Generate CSRF token
if(empty($_SESSION['csrf'])) {
Expand All @@ -16,4 +16,6 @@ if(isset($_POST['csrf']) && $_POST['csrf'] === $_SESSION['csrf']) {
?>
```

Edge cases like AJAX requests and applications running across multiple domains require extra considerations. More about CSRF can be found in the [PHP Security Guide](https://php.net/manual/en/security.csrf.php).
Visit the following resources to learn more:

- [@official@Security Guide](https://php.net/manual/en/security.csrf.php)
6 changes: 5 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ if (($handle = fopen("sample.csv", "r")) !== FALSE) {
}
```

In this snippet, PHP reads through each line of the `sample.csv` file, converting each into an array with `fgetcsv()`. You can study more about CSV processing in PHP via the official [PHP documentation](https://php.net/manual/en/ref.fileinfo.php).
In this snippet, PHP reads through each line of the `sample.csv` file, converting each into an array with `fgetcsv()`.

Visit the following resources to learn more:

- [@official@CSV Processing](https://php.net/manual/en/ref.fileinfo.php)
7 changes: 6 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ if(curl_errno($ch)){

curl_close($ch);
```
In this code, we initialize a cURL session, set its options, execute it, then close the session. We also included error handling. PHP's cURL functions are documented in detail at [PHP.net](https://www.php.net/manual/en/book.curl.php).

Visit the following resources to learn more:

- [@official@cURL](https://curl.se/)
- [@opensource@curl/curl](https://github.com/curl/curl)
- [@official@cURL in PHP](https://www.php.net/manual/en/book.curl.php)
4 changes: 3 additions & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ $decimalNumber = 12.34; // Floating-point number
$boolean = true; // Boolean
```

For a deeper dive into PHP's data types, you can check out the official [PHP documentation](https://www.php.net/manual/en/language.types.php).
Visit the following resources to learn more:

- [@official@Data Types](https://www.php.net/manual/en/language.types.php)
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 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. Check out the [Laravel's migrations documentation](https://laravel.com/docs/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).
2 changes: 1 addition & 1 deletion src/data/roadmaps/php/content/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Database transactions in PHP refer to a unit of work performed within a database

Visit the following resources to learn more:

- [@official@PHP Documentation - PDO Transactions](https://www.php.net/manual/en/pdo.transactions.php)
- [@official@PDO Transactions](https://www.php.net/manual/en/pdo.transactions.php)
Loading

0 comments on commit 6c099db

Please sign in to comment.