Skip to content

Update DateFormat.php to fix deprecated method call: PHP >= 5.5.0. #5295

Closed
wants to merge 1 commit into from

5 participants

@hickeroar

In versions of PHP >= 5.5.0, the method IntlDateFormatter::setTimeZoneId() is deprecated and IntlDateFormatter::setTimeZone() should be used instead.

This is my first proposed zf fix, so hopefully the ternary + dynamic method name var is acceptable.

@hickeroar hickeroar Update DateFormat.php
In versions of PHP >= 5.5.0, the method IntlDateFormatter::setTimeZoneId() and IntlDateFormatter::setTimeZone() should be used instead.

This is my first proposed zf fix, so hopefully the ternary + dynamic method name var is acceptable.
e3288cc
@Maks3w
Zend Framework member
Maks3w commented Oct 20, 2013

Is it need to do a runtime check for this? I suggest let this as is until ZF reach minimum PHP 5.5

@hickeroar

Well, I'll put it this way, I'm using PHP5.5 and I ended up writing my own solution instead of using this class because every time I tried to use it it would give PHP notices.

Also, since the Travis system that runs the unit tests wasn't failing on this during the php5 tests before, its likely that the unit tests aren't testing all scenarios. Sadly my knowledge ends there or I'd dig more into why that is.

@marc-mabe marc-mabe commented on the diff Oct 21, 2013
library/Zend/I18n/View/Helper/DateFormat.php
@@ -133,8 +133,11 @@ public function setTimezone($timezone)
{
$this->timezone = (string) $timezone;
+ // The method setTimeZoneId is deprecated as of PHP 5.5.0
+ $setTimeZoneMethodName = version_compare(PHP_VERSION, '5.5.0', '<') ? 'setTimeZoneId' : 'setTimeZone';
@marc-mabe
Zend Framework member
marc-mabe added a note Oct 21, 2013

Please change against PHP_VERSION* constants (http://www.php.net/manual/reserved.constants.php#reserved.constants.core)

@mwillbanks
mwillbanks added a note Oct 21, 2013

@hickeroar yes; as @marc-mabe said use the PHP_VERSION constants; the version_compare has odd results due to distribution specific areas and can cause issues.

@hickeroar
hickeroar added a note Oct 21, 2013

Sorry, but I'm not sure I understand what you mean. I copied the version_compare line from earlier in the file when I created this line. Link: https://github.com/zendframework/zf2/blob/master/library/Zend/I18n/View/Helper/DateFormat.php#L93

Can you explain what I should change about it? Sorry if that's a dumb question. :-)

@marc-mabe
Zend Framework member
marc-mabe added a note Oct 21, 2013

You should write if (PHP_VERSION_ID < 50500) { because using version_compare() is much slower and the constant PHP_VERSION can contain some special version suffixes the function could be incompatible with.

@Maks3w
Zend Framework member
Maks3w added a note Oct 21, 2013

I think that we can let as is and later @marc-mabe can send a PR improving the performance along all the framework.

@marc-mabe
Zend Framework member
marc-mabe added a note Oct 21, 2013

@Maks3w this was already done 2 month ago : #4980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney added a commit that referenced this pull request Oct 23, 2013
@weierophinney weierophinney [#5295] incorporate feedback
- Use more reliable version comparison
4590ef7
@weierophinney weierophinney added a commit that referenced this pull request Oct 23, 2013
@weierophinney weierophinney [#5295] consistent version checking
- use PHP_VERSION_ID always
- comparison should be against integers
5cd2aae
@weierophinney weierophinney added a commit that closed this pull request Oct 23, 2013
@weierophinney weierophinney Merge branch 'hotfix/5295'
Close #5295
9ba4ae1
@weierophinney weierophinney added a commit that referenced this pull request Oct 23, 2013
@weierophinney weierophinney Merge branch 'hotfix/5295' into develop
Forward port #5295

Conflicts:
	library/Zend/I18n/View/Helper/DateFormat.php
304c42e
@weierophinney
Zend Framework member

I incorporated the feedback on the version comparisons when merging.

@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zf2#5295 from hickeroar/patch-1
Update DateFormat.php to fix deprecated method call: PHP >= 5.5.0.
c762d3c
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zf2#5295] incorporate feedback
- Use more reliable version comparison
c9ac507
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zf2#5295] consistent version checking
- use PHP_VERSION_ID always
- comparison should be against integers
088bad2
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5295' 7b26586
@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/5295' into develop
Forward port zendframework/zf2#5295

Conflicts:
	library/Zend/I18n/View/Helper/DateFormat.php
7a1829c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.