67

T_PAAMAYIM_NEKUDOTAYIM sounds really exotic, but most certainly absolutely nonsense to me. I traced it all down to this lines of code:

<?php
Class Context {
    protected $config;

    public function getConfig($key) { // Here's the problem somewhere...
    $cnf = $this->config;
    return $cnf::getConfig($key);
    }

    function __construct() {
    $this->config = new Config();
    }
}
?>

In the constructor I create a Config object. Here's the class:

final class Config {
    private static $instance = NULL;
    private static $config;

    public static function getConfig($key) {
    return self::$config[$key];
    }

    public static function getInstance() {
    if (!self::$instance) {
        self::$instance = new Config();
    }
    return self::$instance;
    }

    private function __construct() {
    // include configuration file
    include __ROOT_INCLUDE_PATH . '/sys/config/config.php'; // defines a $config array
    $this->config = $config;
    }
}

No idea why this doesnt work / what the error means...

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • possible duplicate of [PHP expects T\_PAAMAYIM\_NEKUDOTAYIM?](http://stackoverflow.com/questions/592322/php-expects-t-paamayim-nekudotayim) – John Slegers Jul 04 '15 at 14:32

8 Answers8

73

T_PAAMAYIM_NEKUDOTAYIM is the double colon scope resolution thingy PHP uses - ::

Quick glance at your code, I think this line:

return $cnf::getConfig($key);

should be

return $cnf->getConfig($key);

The first is the way to call a method statically - this code would be valid if $cnf contained a string that was also a valid class. The -> syntax is for calling a method on an instance of a class/object.

benlumley
  • 11,370
  • 2
  • 40
  • 39
  • This sounds like a near-perfect reason to *never* contemplate using PHP. Surely it wouldn't have been so hard to produce a decent error message? – paxdiablo Dec 27 '09 at 14:09
  • 14
    It's Hebrew -- because Zend Engine has initially been developped by Andi Gutmans and Zeev Suraski, who are from Israel (see http://en.wikipedia.org/wiki/Zend_Engine ) – Pascal MARTIN Dec 27 '09 at 14:14
  • 21
    From Wikipedia: "In PHP, the scope resolution operator is also called Paamayim Nekudotayim (Hebrew: פעמיים נקודתיים‎, pronounced [paʔaˈmajim nəkudoˈtajim]), which means "twice colon" or "double colon" in Hebrew" -> Facing the fact that 99,9% of all dev's won't speak Hebrew very well, I must commit: I love Objective-C. And now I know why. – openfrog Dec 27 '09 at 14:19
  • 12
    @openfrog & @paxdiablo : you are OK to spend weeks/months/years learning programming, algorithm, and new programming languages, but are not OK when you see something "new/special" in PHP ? Come on, how long did it take you to understand what classes, interfaces, inheritance and all that are ? And how long for the two "paamayim nekudotayim" words ? I don't say those are not "strange", but it's not such a catastrophy either, is it ? – Pascal MARTIN Dec 27 '09 at 14:25
  • 31
    @Pascal, if the entire set of error messages was in Hebrew, I'd be happy (though the use of PHP would be curtailed somewhat). But given it's a Hebrew phrase in what is otherwise an English message, it's out of place - how much effort would it take to replace that with the phrase "double-colon" or something else that doesn't require a lookup of an obscure phrase. Just think how much accumulated time is wasted by code-cutters around the world having to look up that phrase. There are enough obstacles in the way when learning a new environment without tossing in artificial ones. – paxdiablo Dec 27 '09 at 14:37
  • 7
    In addition, the stuff I've had to learn re algorithms, language features and so on, has actually been useful outside its immediate area of application. Since I'm unlikely to ever need the Hebrew phrase for double colon outside of PHP, that's a fairly limited piece of education. The fact that this question even had to be asked is testament to the fact that the Hebrew snippet is a bad idea. – paxdiablo Dec 27 '09 at 14:40
  • 4
    Well, at least, once you've gotten this error once, you remember what it means ;-) ;; and I don't thinks it's much harder to understand the meaning of this than to understand how the ?: operator works (for instance -- remember, it's behaviour has been altered with PHP 5.3 ;-) ) ;; but I see your point. – Pascal MARTIN Dec 27 '09 at 14:46
  • @paxdiablo In some ways this is a better than average error message, as Googling for it immediately reveals the meaning. I've encountered plenty of errors in other languages that were generic enough that Googling left me unenlightened. On top of that, I think I've gotten this twice in my whole PHP career. – ceejayoz Sep 23 '11 at 02:52
  • I got this error when I used a variable without the starting `$` in a function: `isset(testvar)` instead of `isset($testvar)`. – SPRBRN Apr 22 '14 at 10:28
  • [T_PAAMAYIM_NEKUDOTAYIM v Sanity](https://philsturgeon.uk/php/2013/09/09/t-paamayim-nekudotayim-v-sanity/) is worth reading imo. – Gui Imamura Oct 08 '15 at 17:15
11

Just my two cents for future visitors who have this problem.

This is the correct syntax for PHP 5.3, for example if you call static method from the class name:

MyClassName::getConfig($key);

If you previously assign the ClassName to the $cnf variable, you can call the static method from it (we are talking about PHP 5.3):

$cnf = MyClassName;
$cnf::getConfig($key);

However, this sintax doesn't work on PHP 5.2 or lower, and you need to use the following:

$cnf = MyClassName;
call_user_func(array($cnf, "getConfig", $key, ...otherposibleadditionalparameters... ));

Hope this helps people having this error in 5.2 version (don't know if this was openfrog's version).

kontur
  • 4,934
  • 2
  • 36
  • 62
tomasofen
  • 1,330
  • 2
  • 12
  • 16
2

if you still need to use the double-colon then make sure your on PHP 5.3+

Justin T. Watts
  • 547
  • 1
  • 4
  • 16
  • 4
    please note [tomasofen's answer](http://stackoverflow.com/a/17333414/499214) is already saying that. Maybe you'd like to upvote it instead of posting your own and fragmenting knowledge? – John Dvorak Aug 19 '13 at 18:34
2

The error is down to an "inappropriate use" of the double colon operator:

return $cnf::getConfig($key);

as by using the :: you're attempting to call a static method of the class itself. In your example you want to call a non-static method on an instantiated object.

I think what you want is:

return $cnf->getConfig($key);
richsage
  • 26,912
  • 8
  • 58
  • 65
2

In your example

return $cnf::getConfig($key)

Probably should be:

return $cnf->getConfig($key)

And make getConfig not static

Question Mark
  • 3,557
  • 1
  • 25
  • 30
1

According to wikipedia, it means a "double colon" scope resolution operator.

http://en.wikipedia.org/wiki/Scope_resolution_operator

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
1

It's the name for the :: operator

Wikipedia

schnaader
  • 49,103
  • 10
  • 104
  • 136
0

For anyone using Laravel. I was having the same error on Laravel 7.0. The error looked like this

syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ';' or ','

It was in my Routes\web.php file, which looked like this

use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use // this was an extra **use** statement that gave me the error

Route::get('/', function () {
    return view('save-online.index');
})->name('save-online.index');
Dharman
  • 30,962
  • 25
  • 85
  • 135
Huzaifa
  • 345
  • 4
  • 15