-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Unhandled exception when using require_once
in config.php
#4286
Comments
To be honest I feel like it's a bug that Unfortunately it looks like changing the cloning behavior is not really viable at this point. The loading order of the So I think the best solution is to document this behavior:
@getkirby/kirby-staff What do you think? Do you see a viable way to make the config file only loaded once, even when the |
Tbh I'm too afraid to touch the clone method as long as we use the Once we have done this, For now, I would definitely add that comment to the guide as @lukasbestle suggests. |
Thinking a bit more about this, maybe I have an idea - let me know what you think, @lukasbestle. With the App class as is, we could add a if ($loadOptions === true) {
$this->optionsFromConfig();
$this->optionsFromProps($props['options'] ?? []);
$this->optionsFromEnvironment($props);
} else {
$this->optionsFromProps($props['options'] ?? []);
} In the close method, we pass false for |
Sounds good. 👍 |
Either I am doing something wrong or this isn't a solution after all - getting many errors with a9917e6 |
The |
Have to admit that I had been trying to solve this quite a bit with develop...fix/4286-config-require-once but just running into too many side effects 🙈 |
Description
When using
require_once
to split up complex site configurations into multiple config files (as recommended in the docs), some Panel actions (e.g. changing the page status) will raise an exception (e.g. changing the page status). Please see below for details instructions to reproduce the issue.I don’t think I’d consider this an issue with Kirby itself. However, it occurs when configuring Kirby using patterns recommended in the official documentation, so I figured creating a bug report would still be appropriate.
Expected behavior
Changing the page status shouldn’t raise an unhandled exception.
Screenshots
To reproduce
tillprochaska/starterkit
.composer start
.http://localhost:8000/panel
.Your setup
Kirby Version
3.6.5
Console output
-/-
Your system (please complete the following information)
-/-
Additional context
I think I've figured out why this issue occurs:
require_once
returnstrue
if the file has already been included before.config.php
will only be loaded once during a request/reponse cycle. Thus, any files required inconfig.php
will also be included only once.num
value, Kirby will attempt to clone the current Kirby instance when changing the page status tolisted
(seePageActions::createNum
).config.php
again. This time, however, callingrequire_once
will returntrue
(instead of the actual configuration from the required file).(This issue might also occur in other situations that cause the Kirby instance to be cloned. I did a quick search for references to
App::clone
and didn’t find similar code paths, but I might have missed something.)I guess the simplest (best?) solution to this problem is to always use
require
instead ofrequire_once
when including files inconfig.php
. If you agree, I think the docs should be updated, possibly even using a warning/callout to make sure new users are aware of the difference between usingrequire
/require_once
. I’d be happy to create a PR! :)(I’m aware that in the case from the repro repo I could have used
num: date
instead ofnum: "{{ page.date.toDate('Ymd') }}"
in the blueprint. However, that’s obviously not a real solution to the underlying problem and won’t work in other cases.)The text was updated successfully, but these errors were encountered: