Discover what the PHP error "unexpected T_PAAMAYIM_NEKUDOTAYIM" means and how to fix it. Learn the story behind this oddly named parse error and how the scope resolution operator (::) works in PHP.

PHP Parse Error: What 'Expecting T_PAAMAYIM_NEKUDOTAYIM' Means in PHP 5.6 (and How to Fix It)

Well, this kind of things only happen with a programming language like PHP (I love it). The PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM (often referred as T_PAAMAYIM_NEKUDOTAYIM) is extremely confusing if you don't understand Hebrew.

"Paamayim Nekudotayim" is Hebrew for "double colon" (::), which in PHP refers to the scope resolution operator. According to the official PHP documentation, The Scope Resolution Operator (also called Paamayim Nekudotayim) is a token that allows access to a constant, static property, or static method of a class or one of its parents. So, basically, this operator is used to access static methods, properties of a class, or constants defined in a class or interface, for example:

// Call a static method
MyClass::staticMethod()

// Retrieve a constant
MyClass::CONSTANT

This operator in PHP is famously known with that name, because Zend, the engine that powers PHP was created by the Israeli Developers Zeeev Suraski and Andi Gutmans. They called the internal token in that way, end of the story. In PHP 4, when you cause a syntax error that involves the :: operator, the error would always contain the famous phrase: "unexpected T_PAAMAYIM_NEKUDOTAYIM".

How to trigger this parse error

One of the simplest examples to trigger the exception is the following one:

<?php

echo Namespace::testing();

This code triggers the exception because since PHP 5.3 namespace is a keyword thanks to the namespace feature. The parse error occurs as the PHP interpreter resolves Namespace::testing as a namespace name, confusing seeing the scope resolution operator (::) and therefore, displays the famous parse error.

How to fix it?

  1. Be sure to check for missing function names, constants, or class names after the operator ::.
  2. Be sure that the syntax is complete. For example, you might be calling a static method without providing its name (Class:: without something after).
  3. If you're accessing constants or static methods dynamically, ensure you're using the correct syntax.

Conclusions

If you ever get that odd-looking parse error PAAMAYIM NEKUDOTAYIM, PHP is telling you that:

  1. You're using :: in a place of your code where isn't expected.
  2. You're using :: after an invalid expression or variable.
  3. You're using :: on a non-class identifier.
  4. You're using incorrectly the inheritance feature or static calls.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors