XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

Usage of reserved names for PHP7 #133

Closed camsjams closed 8 years ago

camsjams commented 8 years ago

This library doesn't work in PHP 7 = Cannot use Handlebars\String as String because 'String' is a special class name.

JustBlackBird commented 8 years ago

We could replace \Handlebars\String with \Handlebars\UnsafeString to play nice with PHP7 but it can break backward compatibility. What do you think @fzerorubigd ?

everplays commented 8 years ago

We can just check the php version and load a different class. And to avoid maintaining duplicate code, either they can both inherit from one class or we can use traits.

everplays commented 8 years ago

Even simpler: We can have \Handlebars\UnsafeString as main implementation just like you suggested and extend \Handlebars\String from it (making it deprecated). Nothing else is required for this as php 7 users will stick to \Handlebars\UnsafeString and others will continue using \Handlebars\String.

JustBlackBird commented 8 years ago

@everplays the second option (about inheritance) you've proposed could be the way to go. I'll try to implement a PR for that soon.

JustBlackBird commented 8 years ago

Actually the situation is more complicated than I thought before. Here \Handlebars\String is used to wrap template contents. Do we need one more string class (lets say \Handlebars\TemplateString) for such usage?

everplays commented 8 years ago

@JustBlackBird this part should be checked with an if statement. If the version is 7, only check against UnsafeString. Otherwise, both UnsafeString and String.

mfeltscher commented 8 years ago

Could you please release a new version containing #135 ?

Thanks!

everplays commented 8 years ago

I just tagged v0.10.3. Enjoy.

mfeltscher commented 8 years ago

Thank you! PHP 7 here we come! :)