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

Make CodeIgniter::context nullable to handle access before initialization #5708

Merged
merged 1 commit into from
Feb 19, 2022

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Feb 18, 2022

@kenjis this is to handle context is accessed before initialized as decribed at #5650 (comment) on composer update && php spark serve, tested in php 8.1

php builds development
composer update
php spark serve

Before

CodeIgniter v4.1.8 Command Line Tool - Server Time: 2022-02-18 17:42:23 UTC-06:00

An uncaught Exception was encountered

Type:        Error
Message:     Typed property CodeIgniter\CodeIgniter::$context must not be accessed before initialization
Filename:    /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php
Line Number: 308

        Backtrace:
                                                -48 - /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CLI/Console.php::run
                                                                -57 - /Users/samsonasik/www/ci4-prj/spark::run

After

CodeIgniter v4.1.8 Command Line Tool - Server Time: 2022-02-18 17:47:40 UTC-06:00

An uncaught Exception was encountered

Type:        AssertionError
Message:     Context must be set before run() is called. If you are upgrading from 4.1.x, you need to merge `public/index.php` and `spark` file from `vendor/codeigniter4/framework`.
Filename:    /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php
Line Number: 309

        Backtrace:
                                                -309 - /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php::assert
                                                                -48 - /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CLI/Console.php::run
                                                                -57 - /Users/samsonasik/www/ci4-prj/spark::run

Checklist:

  • Securely signed commits

@samsonasik
Copy link
Member Author

@kenjis here is the proof:

without initialization, got A::$context must not be accessed before initialization : https://3v4l.org/3afAK
with initialization, got Context must be set before run() is called : https://3v4l.org/DFddo

@samsonasik samsonasik requested a review from kenjis February 18, 2022 23:59
@samsonasik
Copy link
Member Author

I am merging early so user that uses develop version can immediately see the clue in the error message.

@samsonasik samsonasik merged commit eb09acd into codeigniter4:develop Feb 19, 2022
@samsonasik samsonasik deleted the make-context-nullable branch February 19, 2022 00:02
@kenjis
Copy link
Member

kenjis commented Feb 19, 2022

@samsonasik Thank you!

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround on this one.

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 this pull request may close these issues.

3 participants