File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -393,4 +393,6 @@ Release Date: Unreleased
393393
394394## Bugs Fixed
395395
396+ - ** Config:** Fixed a bug where instantiating an anonymous ` BaseConfig ` subclass threw a ` ValueError ` from ` getenv() ` on PHP 8.6.
397+
396398See the repo's [ CHANGELOG.md] ( https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md ) for a complete list of bugs fixed.
Original file line number Diff line number Diff line change @@ -175,6 +175,10 @@ public function __construct()
175175
176176 $ this ->registerProperties ();
177177
178+ if (str_contains (static ::class, "\0" )) {
179+ return ; // PHP 8.6 getenv() throws for names with null bytes, as in anonymous class names
180+ }
181+
178182 $ values = get_object_vars ($ this );
179183 $ properties = array_keys ($ values );
180184 $ prefix = static ::class;
Original file line number Diff line number Diff line change 4040use Tests \Support \Config \MergeRegistrarA ;
4141use Tests \Support \Config \MergeRegistrarB ;
4242use Tests \Support \Config \TestRegistrar ;
43+ use ValueError ;
4344
4445/**
4546 * @internal
@@ -137,6 +138,27 @@ public function testBasicValues(): void
137138 $ this ->assertSame (18 , $ config ->golf );
138139 }
139140
141+ public function testAnonymousSubclassSkipsEnvironmentOverrides (): void
142+ {
143+ $ dotenv = new DotEnv ($ this ->fixturesFolder , '.env ' );
144+ $ dotenv ->load ();
145+
146+ $ named = new SimpleConfig ();
147+ $ alpha = null ;
148+
149+ $ exception = null ;
150+
151+ try {
152+ $ alpha = (new class () extends SimpleConfig {})->alpha ;
153+ } catch (ValueError $ exception ) {
154+ // ...
155+ }
156+
157+ $ this ->assertNull ($ exception , 'BaseConfig should skip environment overrides for anonymous subclasses. ' );
158+ $ this ->assertSame ('pow ' , $ named ->alpha );
159+ $ this ->assertSame ('one ' , $ alpha );
160+ }
161+
140162 public function testUseDefaultValueTypeIntAndFloatValues (): void
141163 {
142164 $ dotenv = new DotEnv ($ this ->fixturesFolder , '.env ' );
You can’t perform that action at this time.
0 commit comments