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?
- Be sure to check for missing function names, constants, or class names after the operator
::
. - Be sure that the syntax is complete. For example, you might be calling a static method without providing its name (Class:: without something after).
- 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:
- You're using
::
in a place of your code where isn't expected. - You're using
::
after an invalid expression or variable. - You're using
::
on a non-class identifier. - You're using incorrectly the inheritance feature or static calls.
Happy coding ❤️!