PHP-PHP _LARAVEL-OPERATOR-SUMMARY

Objectives: PHP-PHP _LARAVEL-OPERATOR-SUMMARY

Laravel Facades, PHP :: Operator, and Core PHP Operators — Quick Guide

Laravel Route, Artisan, the PHP :: Operator, and Other PHP Operators

A compact, beginner-friendly reference with clear examples.

1) What does use Illuminate\Support\Facades\Route; mean?

  • use imports a class/namespace so you can reference it by its short name.
  • Illuminate\Support\Facades\Route is Laravel’s Facade for routing; it gives you methods like Route::get(), Route::post(), etc.
// routes/web.php or routes/api.php
use Illuminate\Support\Facades\Route;

Route::get('/hello', function () {
    return 'Hello World';
});

Without use you’d have to write the fully qualified name every time:

\Illuminate\Support\Facades\Route::get('/hello', fn () => 'Hello World');

2) What does use Illuminate\Support\Facades\Artisan; mean?

  • The Artisan Facade lets you run Artisan commands from PHP code (not just the terminal).
use Illuminate\Support\Facades\Artisan;

Artisan::call('cache:clear');
Artisan::call('migrate', ['--force' => true]);

Typical places: jobs, controllers, maintenance scripts. Use carefully to avoid long-running tasks in HTTP requests.

3) The PHP :: (Scope Resolution Operator)

  • Used to access static methods, static properties, and class constants without creating an object.
  • Also resolves parent class members (e.g., parent::method()).
  • No spaces allowed between the colons — : : is a syntax error.
class Calculator {
    public static function add($a, $b) { return $a + $b; }
    const VERSION = '1.0.0';
}

echo Calculator::add(2, 3);      // 5
echo Calculator::VERSION;        // 1.0.0
echo Calculator::class;          // "Calculator" (class name as string)
Invalid: Calculator: :add(2,3) ❌ — spaces break the operator.

4) :: vs ->

Use :: for static/contextual class access

class AppInfo {
    public static function name() { return 'MyApp'; }
    const BUILD = 42;
}

echo AppInfo::name();
echo AppInfo::BUILD;
No object needed

Use -> for object instances

class User {
    public string $name = 'Ada';
    public function greet() { return "Hi, {$this->name}"; }
}

$u = new User();
echo $u->name;    // property
echo $u->greet(); // method
Requires an object

5) Other PHP Operators (Quick Reference)

Comparison

  • == loose equality (type juggling): 5 == "5"true
  • === strict equality (type + value): 5 === "5"false
  • !=, !==, <, <=, >, >=
  • <=> spaceship (returns -1, 0, 1 for <, =, >)

Assignment / Arithmetic / String

  • =, +=, -=, *=, /=, %=
  • . string concatenation; .= append

Logical

  • &&, ||, ! (common)
  • and, or, xor (lower precedence; use carefully)

Null/Coalescing/Elvis

  • ?? null coalescing: $name = $_GET['name'] ?? 'Guest';
  • ?: elvis (truthy check): $title = $givenTitle ?: 'Untitled';

Ternary

  • condition ? if_true : if_false

Array/Iteration

  • => key => value
  • ... spread/unpack (arrays/arguments)

Bitwise

  • &, |, ^, ~, <<, >>

Type / Object

  • instanceof (type checking)
  • -> object access (instance)
  • :: scope resolution (static/constant/class name)
  • new create object

Miscellaneous

  • @ error control (avoid in production)
  • clone object cloning
  • yield generators
  • match (PHP 8) expression-like switch

6) When should I use each file/operator?

Goal Use Example Why
Define web pages (HTML, sessions, CSRF) routes/web.php + Route Facade Route::get('/dashboard', [DashController::class, 'index']) Browser flows need sessions & CSRF
Define API endpoints (JSON, stateless) routes/api.php + Route Facade Route::post('/login', [AuthController::class, 'login']) No sessions; token-based auth; auto /api prefix
Run terminal tasks in code Artisan Facade Artisan::call('queue:work', ['--once' => true]) Trigger CLI commands programmatically
Access a static method/constant :: operator Config::get('app.name'), App::class Static access; no object required
Call a method on an object -> operator $user->notify($n) Instance method/property access

Tip: Keep :: with no spaces. If you see a syntax error around colons, check you didn’t write : :.

You can paste this whole page into a .html file and open it to study offline.

Reference Book: N/A

Author name: SIR H.A.Mwala Work email: biasharaboraofficials@gmail.com
#MWALA_LEARN Powered by MwalaJS #https://mwalajs.biasharabora.com
#https://educenter.biasharabora.com

:: 1::