1

I am getting the following error ever since I upgraded from PHP 5.2x or 5.3x (not sure which) to 5.4x:

syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE

The following is the code that generates the error. Essentially I have a class to create SVG image with a static draw() method defined in a derived class and a static helper function drawPng() on the base class that converts the SVG to PNG using Imagick. The error is at the marked line.

static function drawPng($filename, $data, &$options=array()) {
    ob_start();
    static::draw($data, $options); // <-- Error occurs
    $svg = ob_get_clean();

    $im = new Imagick();
    if(!$im) die('Imagick not installed');
    $bg = (empty($options['background']) ? 'transparent' : $options['background']);
    $im->setBackgroundColor(new ImagickPixel($bg));
    $im->readImageBlob($svg);
    $im->setImageFormat('png');
    if($filename) $im->writeImage($filename);
    else echo $im->getImageBlob();
}

The code as shown above has worked until the upgrade. Thanks for the assistance.

steveo225
  • 11,394
  • 16
  • 62
  • 114
  • Did you change your php.ini during the upgrade ? – Mayur Nagekar Apr 09 '15 at 13:22
  • `T_PAAMAYIM_NEKUDOTAYIM` means "double colon". Try `self::draw` rather than `static::draw` maybe? – ceejayoz Apr 09 '15 at 13:23
  • http://stackoverflow.com/q/1966010/419 – Kev Apr 09 '15 at 13:23
  • Are you sure that code worked before the upgrade? [LSB](https://php.net/manual/en/language.oop5.late-static-bindings.php) was added in 5.3 – TiiJ7 Apr 09 '15 at 13:27
  • Maybe I was on 5.3. My webhost upgraded to 5.4 without telling me, and yes, this has worked for the last 6 months until the upgrade – steveo225 Apr 09 '15 at 13:29
  • @TiiJ7 Ok, that was the problem. My webhost removed PHP 5.3 and replaced it with PHP 5.4. When my site failed to render without errors in PHP 5.4, they reverted back to PHP 5.2 failsafe, which doesn't understand LSB. Thanks for the help, now I have a fun phone call to make – steveo225 Apr 09 '15 at 13:38

2 Answers2

3

T_PAAMAYIM_NEKUDOTAYIM is the hebrew name (for some reason - Zend was started by Israelis folk, as ceejayoz pointed out. ) for the double colon, aka ::

Change static to self:

static::draw($data, $options);

self::draw($data, $options);
Andrei
  • 3,434
  • 5
  • 21
  • 44
  • 1
    The "for some reason" is Zend was started by Israelis. – ceejayoz Apr 09 '15 at 13:25
  • Well, I did not know that. I do now though. – Andrei Apr 09 '15 at 13:27
  • That didn't work, the error says: `Call to undefined method Chart::draw()` which it doesn't because that method is in the derived class – steveo225 Apr 09 '15 at 13:28
  • I'm sure you already know this, `self` refers to the current working class in a static context. So you do need the `draw` method to be in the current class and be static. – Andrei Apr 09 '15 at 13:32
0

I think you messed up the PHP versions and actually starting this code on PHP 5.2. This error would happen in PHP 5.2 because there is no static:: access. Also the error message with T_PAAMAYIM_NEKUDOTAYIM in PHP 5.4 would mention "::", while yours doesn't, which is another hint that you're running wrong version of PHP.

To verify add echo phpversion(); exit(); to the top of this method.

astax
  • 1,769
  • 1
  • 14
  • 23
  • As I stated in a comment above, my webhost removed PHP 5.3 and replaced it with PHP 5.4. When my site failed to render without errors in PHP 5.4, they reverted back to the PHP 5.2 failsafe, which doesn't understand LSB. Not sure why webhosts change things without running it by their customers first. A new webhost may be in my future. – steveo225 Apr 09 '15 at 13:50
  • 1
    @steveo225 - "they reverted back to the PHP 5.2 failsafe" - ouch, what a bizarre approach. – Kev Apr 09 '15 at 13:52
  • Agreed. They always keep 2 PHP versions installed and let the user choose, but the older version is also a failsafe when issues arise. I think they do this because so many older scripts don't work in the newer versions of PHP and people don't fix them, or at least that is what they hinted to me – steveo225 Apr 09 '15 at 13:57
  • So can you switch to PHP 5.3 then? Just do this and the error will be gone. – astax Apr 09 '15 at 14:00
  • I'd definitely switch hosts if 5.2 is considered "failsafe" - it hasn't been updated for security in over four years. Eek! – ceejayoz Apr 09 '15 at 14:02