Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

If you’re here right now, it’s safe to say you don’t speak Hebrew.

PAAMAYIM – Represents the Hebrew word for double

NEKUDOTAYIM – Represents the Hebrew word for colon

This gem was included in Zend Engine 0.5 that powered PHP 3. The developer team hails from Israel and it would appear that there was a problem involving translation.

Solving The Error

The operator is named the Scope Resolution Operator and it is used to reference base classes or class methods without prior instantiation. A quick example of how to use scope resolution properly is below.

1
2
3
4
5
6
7
class Project_Forms_MyValidator
{
    static public function capitalizeString($string)
    {
        return ucwords($string);
    }
}
class Project_Forms_MyValidator
{
    static public function capitalizeString($string)
    {
        return ucwords($string);
    }
}
1
2
3
$string = 'this title should be properly capitalized';
 
echo Project_Forms_MyValidator::capitalizeString($string);
$string = 'this title should be properly capitalized';

echo Project_Forms_MyValidator::capitalizeString($string);

Note the use of the static keyword for the capitalizeString() method. Without it, an E_STRICT error would be thrown.

The key to solving this error is understanding when to use the scope resolution operator and when to use the object operator (->). If you have instantiated an object you will use the object operator to access the object. Following the example above, we can see this in action:

1
2
3
4
5
6
7
class Project_Forms_MyValidator
{
    public function capitalizeString($string)
    {
        return ucwords($string);
    }
}
class Project_Forms_MyValidator
{
    public function capitalizeString($string)
    {
        return ucwords($string);
    }
}
1
2
3
4
$string = 'this title should be properly capitalized';
$validator = new Project_Forms_MyValidator();
 
echo $validator->capitalizeString($string);
$string = 'this title should be properly capitalized';
$validator = new Project_Forms_MyValidator();

echo $validator->capitalizeString($string);

In this case we remove the static keyword on the capitalizeString() method and instead instantiate the object before accessing its methods. This has benefits over static calls, since you are able to access the object variables in addition to its methods.

Discussion

Leave a Reply