Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overridden functions ignore declare(strict_types=1) #43

Open
Nebual opened this issue Jan 14, 2019 · 0 comments · May be fixed by #44
Open

Overridden functions ignore declare(strict_types=1) #43

Nebual opened this issue Jan 14, 2019 · 0 comments · May be fixed by #44

Comments

@Nebual
Copy link

Nebual commented Jan 14, 2019

PHP 7.0 added declare(strict_types=1);, which enables strict type checking of all method calls made in a file with that declaration, including internal functions such as strtotime(). https://wiki.php.net/rfc/scalar_type_hints_v5#strict_types_declare_directive

Timecop seems to be clobbering these type checks, resulting in no typechecking on calls made to overridden functions, as if strict_types wasn't enabled.

The following script, when run without timecop enabled, will fatally error "strtotime() expects parameter 1 to be string, null given" (as is correct). With timecop, the error is suppressed, causing execution to continue to show 'End!':

<?php
declare(strict_types=1);

strtotime(null); // fatal error without timecop, silent success with timecop
echo "End!\n";

This resulted in fatal errors being thrown in our Production environment, which do not occur in our Testing environment, as the latter uses Timecop. While those erroneous nulls should be patched, it was pretty confusing to trace down the in-production-only error, and I suspect this is likely to happen to others as the intended usage of Timecop is to be run in testing only.

Nebual added a commit to Nebual/php-timecop that referenced this issue Jan 14, 2019
@Nebual Nebual linked a pull request Jan 14, 2019 that will close this issue
cs278 added a commit to kiddivouchers/php-timecop that referenced this issue Sep 27, 2019
hnw#44

* hnw/pr/44:
  Support strict_types=1 for overridden functions Fixes hnw#43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant