Skip to content

Instantly share code, notes, and snippets.

@MuhammadQuran17
Last active November 26, 2025 11:04
Show Gist options
  • Select an option

  • Save MuhammadQuran17/28ac597035f81354a7a7ac9f29ab83bb to your computer and use it in GitHub Desktop.

Select an option

Save MuhammadQuran17/28ac597035f81354a7a7ac9f29ab83bb to your computer and use it in GitHub Desktop.
Code sheat

Update php in VPS

sudo apt install -y \
php8.3 \
php8.3-cli \
php8.3-common \
php8.3-mysql \
php8.3-xml \
php8.3-mbstring \
php8.3-curl \
php8.3-zip \
php8.3-bcmath \
php8.3-gd \
php8.3-intl \
php8.3-soap \
php8.3-readline \
php8.3-pgsql \
php8.3-sqlite3
  1. update-alternatives --config php select 8.3
  2. Reconfigure apache2
a2dismon php7.4 2>/dev/null || true
a2enmod php8.3
systemctl restart apache2
  1. You can check php_info() in some dummy file.

Default Apache 2 conf for laravel folder

<VirtualHost *:80>
    ServerName cetafmets.uz
    DocumentRoot /var/www/html/myproject/public

    <Directory /var/www/html/myproject/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Null Coalescing (??) vs Ternary (?:) operators

  • Null coalescing - check for null and performs next (?? ??=)
  • Ternary - check for false and performs next (?:)

Caching Opcache

OPcache works by storing the precompiled script bytecode in shared memory, not the original source files themselves. This eliminates the need for PHP to load, parse, and compile the human-readable code on each request, significantly boosting performance. The reason your changes to StatusMapper are not reflected immediately is that OPcache is serving the old, cached bytecode from memory.

<?php
opcache_reset();
echo "OPcache has been cleared successfully!";
?>

Oneline if

if (is_string($hashesForCherryPick)) $hashesForCherryPick = explode(" ", $hashesForCherryPick);

If you concatenate false with a string, PHP will turn it into an empty string ("").

Testing

Functional and Unit testing

  • Functional tests only in and out. Your soft becomes black-box, it kind of user behavior simulation
  • Unit tests inside of classes, how they were designed. Test component in an isolated way.

Stubs and Mocks

  • Stubs are fake objects, thatreturns something that you expect (API response, data)
  • Mocks are more advanced, they test behavior of a method (how much method was called, with what arguments, in what order)

Install composer

cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

# to check 
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer  

composer -v

CI CD

Github actions

  1. We can see how it was configured in most popular open-sorce workflows. For example in https://github.com/nunomaduro/collision/actions/runs/18556937305/workflow?pr=337#L29
image

Or in https://github.com/pestphp/pest/actions/runs/18678438076/workflow PEST

Or in https://github.com/laravel/framework/actions/runs/19550739797/workflow?pr=57841 Laravel Framework

Class

  1. Class member variables are called properties

Functions

Arguments vs Parameters

  • Parameters: Parameters are the variables listed inside the parentheses in a function's definition. They act as placeholders for the values that will be passed into the function when it's called. Think of them as the function's "input specifications."
  • Arguments: Arguments are the actual values that are passed to a function when it's called. They are the real data that the function will use during its execution. Think of them as the function's "actual inputs."
<?php

function add($num1, $num2) { // $num1 and $num2 are parameters
    return $num1 + $num2;
}

$result = add(5, 3); // 5 and 3 are arguments

echo $result; // Output: 8

Exceptions

Custom Exception

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment