0

Is there a reason why this would cause a 500 error? Something to do with when it's executed and what's available, or am I using __DIR__ incorrectly?

class MyClass
{

   public $filepath = __DIR__ . "/../downloads";

}
d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • Are you trying to get `dirname(__DIR__)`? – Lewis May 18 '14 at 17:47
  • I was hoping to just store `/path/to/file` as a string. That's how I've always used `__DIR__` in the past. – d-_-b May 18 '14 at 17:48
  • I assume your php version is >= 5.3? –  May 18 '14 at 17:51
  • @Layne `5.3.3`, correct – d-_-b May 18 '14 at 17:52
  • Well the first one makes sense that it isn't working but the second one is a question mark for me especially since it's working for me. Remember that `__DIR__` isn't a constant (first example). –  May 18 '14 at 17:56
  • 2
    Side-note: The first one should work as of PHP 5.6 - in fact, it's the [first listed new feature](http://docs.php.net/manual/en/migration56.new-features.php). – Niet the Dark Absol May 18 '14 at 17:58
  • @Layne I think you're right, the second one works - must've had some other error. Still interested to know about the first. Must be a timing issue is my guess... – d-_-b May 18 '14 at 18:00
  • @NiettheDarkAbsol, shouldn't matter for `properties`. The added undefined variable `constants` at compile time in 5.6, but it's worked on `properties` for quite a while. – Mark Tomlin May 18 '14 at 18:08
  • you can not assign an expression to the class property when declare. Only scalar value. So you can not concatenate there. – Deadooshka May 18 '14 at 18:08

0 Answers0