shield: Bug: [CI4.5.0] Cannot declare class Shield\Config\Auth
PHP Version
8.1
CodeIgniter4 Version
4.5.0
Shield Version
dev-develop
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MySQL 5.6
Did you customize Shield?
I think so, I use App/ThirdParty/Shield
What happened?
I just updated new codeigniter v4.5.0 and got this error.
Steps to Reproduce
…
Expected Output
…
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 3 months ago
- Comments: 19 (12 by maintainers)
Commits related to this issue
- fix: Cannot declare class Shield\Config\Auth, because the name is already in use See https://github.com/codeigniter4/shield/issues/1091 — committed to kenjis/CodeIgniter4 by kenjis 3 months ago
@jlopes90 Thank you for your report. This bug was resolved in version CI4.5.1. Please use the latest version of the CI framework.
@kenjis thanks!
Try this: https://github.com/codeigniter4/CodeIgniter4/pull/8745
Without
ThirdParty/Shield
, just inside theapp
sometimes it makes me confused searching or lost.Workaround:
app/Config/Autoload.php
:Thanks! I got
PHP Fatal error: Cannot declare class Shield\Config\Auth, because the name is already in use
.Make sure you delete file App\Config\Auth.php.
I’m using composer and
shield (dev-develop)
was already installed.It’s not about taking everything and passing it to
ThirdParty/Shield
. What I’m doing is separating and not mixing within app, for example:So what I did was take
Auth.php
,AuthGroup.php
and others and move it toThirdParty/Shield
, it’s easier to configure inside a shield folder.I don’t know why people don’t want to use app. But what is clear is that many people do not use app. Except for this report, we have seen cases before, I saw another example in shield_oauth Repo .
In any case, the behavior of
config('Auth')
is different in both versions 4.4.8 and 4.5.0.@kenjis, Install Codeigniter and Shield with Composer.
CI 4.4.8:
app\ThirdParty\Shield\Config\Auth.php:
See http://localhost:8080/login Everything is fine. Pay attention, this is the
namespace Shield\Config;
.CI 4.5.0: Install Codeigniter 4.5.0 and Shield with Composer.
app\ThirdParty\Shield\Config\Auth.php:
See http://localhost:8080/login HOMM!
How to fix? with :
But why?
Delete file App\Config\Auth.php if it exists. Then change file Shield\Config\Auth.php as follows.
https://forum.codeigniter.com/showthread.php?tid=90586&pid=417671#pid417671