PHP Symbols Reference: What do ->, ::, @ and others mean?

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

PHP Symbols Reference: From -> to ... — What Do They Really Mean?

\n\n

Have you ever looked at someone else's PHP code and felt like you were reading ancient hieroglyphs? Arrows, colons, strange question marks — all of this can scare even an experienced developer. In reality, behind each symbol lies a simple and logical concept.

\n\n

We have prepared for you a complete PHP symbols reference that will turn "magic signs" into understandable tools. This guide is based on the most popular question on Stack Overflow and is specially adapted for readers of pythonlib.ru. Let's go!

\n\n

1. Arrow -> (Object Access Operator)

\n\n

The most common "hieroglyph" in object-oriented PHP. The arrow means "get the property or method of this object".

\n\n
class Cat {\n    public $name = 'Murka';\n    public function meow() {\n        return 'Meow!';\n    }\n}\n\n$cat = new Cat();\necho $cat->name;   // Murka\necho $cat->meow(); // Meow!
\n\n

Remember: to the left of the arrow is always an object ($cat), to the right is its property or method without the $ sign.

\n\n

2. Double Colon :: (Scope Resolution Operator)

\n\n

Two colons are used to access static properties and methods, class constants, and to refer to the parent class.

\n\n
class MathHelper {\n    const PI = 3.14;\n    public static function square($x) {\n        return $x * $x;\n    }\n}\n\necho MathHelper::PI;        // 3.14\necho MathHelper::square(5); // 25
\n\n

When you see ::, mentally substitute "static" or "constant". This is the key to understanding.

\n\n

2.1 Special case: parent::

\n\n
class Animal {\n    protected function sound() {\n        return '...';\n    }\n}\n\nclass Dog extends Animal {\n    public function sound() {\n        return parent::sound() . ' Woof!';\n    }\n}
\n\n

3. @ Sign (Error Control Operator)

\n\n

One of the most controversial symbols. @ before an expression suppresses all errors that may occur during its execution.

\n\n
$result = @file_get_contents('http://example.com');\n// If the site is unavailable, the error is not displayed
\n\n

Important: do not overuse @! It complicates debugging. Use it only when you really expect an error and are ready to handle it.

\n\n

4. ?? (Null Coalescing Operator)

\n\n

Appeared in PHP 7.0 and instantly became a developer favorite. It checks whether a variable exists and is not null.

\n\n
$username = $_GET['user'] ?? 'Guest';\n// If $_GET['user'] is not set, 'Guest' is assigned\n\n// Old way:\n$username = isset($_GET['user']) ? $_GET['user'] : 'Guest';
\n\n

Works in a chain: $a ?? $b ?? $c — takes the first non-null value.

\n\n

5. ?-> (Nullsafe Operator)

\n\n

A new feature from PHP 8.0. It allows "safe" access to methods and properties of an object that may be null.

\n\n
class User {\n    public function getAddress() {\n        return new Address();\n    }\n}\n\n// If the user is not logged in — $user = null\n$city = $user?->getAddress()?->city;\n// Instead of a cumbersome check:\n// if ($user && $user->getAddress()) { ... }
\n\n

6. ... (Spread Operator)

\n\n

Three dots "unpack" an array or iterable object. Very convenient for passing arguments to a function or merging arrays.

\n\n
function sum(...$numbers) {\n    return array_sum($numbers);\n}\n\necho sum(1, 2, 3, 4); // 10\n\n// Unpacking an array when passing:\n$nums = [1, 2, 3];\necho sum(...$nums); // 6\n\n// Merging arrays:\n$arr1 = [1, 2];\n$arr2 = [3, 4];\n$merged = [...$arr1, ...$arr2]; // [1, 2, 3, 4]
\n\n

7. <=> (Sp

Blogs

Book Recommendations