Paamayim Nekudotayim

Huh?  If you seen these two words before, you're a PHP developer, and you've just gotten an error message with these two words embedded in the error message.  It usually looks something like this: "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM..."

Paamayim nekudotayim is Hebrew for "double colon."  The words were used by the two original Israeli developers of PHP, Andi Gutmans and Zeev Suraski, for the scope resolution operator, "::".

The first time you run across it in an error message, it throws you for a curve, what the heck?  As you continue to develop in PHP, you find the two words are so distinctive, that you instantly recognize the error message, and you instantly know how to correct the error. As a result, the words have persisted as the scope resolution error message in PHP since it was first used in PHP 3 back in 1997.

What is a scope resolution operator?  It looks like this when your coding, ::, and it is used when you want to use a static method.  Let's use an example, here's a class...

class AnimalSounds
{
   public static function DogBark()
  {
     $bark = "woof, woof, ";
     $numberofBarks = 4;

     while ($numberOfBarks  > 0 )
     {
        echo $bark;
        $numberofBarks--;
     }
  }
}

Since we've made the method DogBark() a static method, we can call the method from anywhere in our application by doing this.


AnimalSounds::DogBark();

The result would be:

woof,woof,woof,woof,woof,woof,woof,woof,

All's well and good.  This is the proper use of the paamayim nekudotayim, ::, scope resolution operator.  It's used with static methods and can be used without instantiating a class.

Knowing what the words mean "::" can instantly clue you in to the error condition.

If you use a :: and you were supposed to use a ->.  In the above example, if the DogBark() method was not static and you called it with :: when you should have instantiated the object and called it with a ->, you'll get this error:

"Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM".

This same error message will also occur if you forget and use a $ sign, as if the class was a variable, in the above example, like so:

$AnimalSounds::DogBark();

This will give you the same error message: "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM". In this case, because of the $, PHP thought that AnimalSounds was a variable instead of a class, and when it ran into ::, it threw the unexpected T_PAAMAYIM_NEKUDOTAYIM error.

By the way, the T_ in the error message stands for "token." You'll find this with other PHP error messages.  It's just the way PHP finds errors.

When the Paamayim Nekudotayim error occurs, look for somewhere in your code where you've used a :: for the cause of the problem.  You'll get so you instantly know what the problem is, and grow to appreciate the Paamayim Nekudotayim error message.


Comments

Paamayim Nekudotayim — 1 Comment

Leave a Reply