JosephLenton / PHP-Error

Better error reporting for PHP, and prettier too!
1.35k stars 151 forks source link

__DIR__ not in PHP <5.3 #14

Closed Geczy closed 12 years ago

Geczy commented 12 years ago

The magic constant __DIR__ isn't available with PHP <5.3

http://php.net/manual/en/language.constants.predefined.php

Geczy commented 12 years ago

You could also opt to do this if you'd like:

<?php 

if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
JosephLenton commented 12 years ago

I'll make the changes for the example files, but I'm not accepting the change to php_error.

The only users that will see T_DIR are those on 5.3 and beyond, and there it is an alias for 'DIR' and not dirname(FILE).

DIR is also only used in php_error for error messages, we aren't actually using the constant DIR. It's so you get "unexpected DIR" instead of "unexpected T_DIR", as the first will be matching actual user code (they have to write an unexpected DIR to get that message).

It's to complement others, such as 'unexpected ::' instead of 'unexpected T_PAAMAYIM_NEKUDOTAYIM'.

I'm planning to just define the numeric tokens for these value if they are not present, with their future values. I'd rather bolt on workarounds for 5.0, then bolt on workarounds that affect 5.3 code, as eventually the 5.0 workarounds could be dropped.