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

Type juggling can be eliminated if these three small changes are made #2326

Closed
John-Betong opened this issue Oct 11, 2019 · 1 comment
Closed

Comments

@John-Betong
Copy link

Describe the bug
I appreciate the reluctance not to use strict_types and if this small change is not allowed I would be grateful to know why the defined type parameter does not match the expected predefined function type parameter.

Numerous functions in the system folder have function parameter types specified and because declare(strict_types=1); is not set then the parameter types are type juggled. No errors are reported even though error_reporting is set to the maximum value of -1.

Changing these three files:
/app/config/Boot/development.php
/app/config/Boot/production.php
/app/config/Boot/testing.php // not tested :)

and defining CI_DEBUG to use boolean parameters instead of integers matches the parameters of "system/Log/Logger.php:155"

The following error log was generated when "system/Log/Logger.php" was declared(strict_types=1);

Uncaught TypeError:
Argument 2 passed to CodeIgniter\Log\Logger::__construct()
must be of the type boolean, integer given,
called in /var/www/ci2/ci4-strict-github/system/Config/Services.php on line 432
and
defined in /var/www/ci2/ci4-strict-github/system/Log/Logger.php:155 Stack trace:

CodeIgniter 4 version
Ver: 4.0.0-rc.2.1

Affected module(s)
system/Log/Logger.php

Expected behavior, and steps to reproduce if appropriate
I did not expect errors to be generated when declare(strict_types=1); was set/

Context

  • OS: [e.g. Windows 99]
  • Web server [e.g. Apache 1.2.3]
  • PHP version [e.g. 6.5.4]
@lonnieezell
Copy link
Member

No errors are reported even though error_reporting is set to the maximum value of -1.

That's because in PHP type-juggling is an integral part of the language until recently. It's not an error, it's a language feature.

In this particular case I don't see anything wrong with changing it. It's possible a few years ago I had other ideas about what to do with that variable. It's unsure.

Feel free to submit a PR. I believe we've told you that before.

I did not expect errors to be generated when declare(strict_types=1); was set/

You cannot expect that to be true when the framework was not developed for, and has no intention of using, strict typing. IIRC you maintain a fork that uses strict typing and that's great. To be brutally honest, though, it's not our place to fix issues that break due to something someone else does in their fork.

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

No branches or pull requests

2 participants