PHP Core Functions – A Weblog of Priyank Maniar https://priyank.rocks Articles on web development & mobile app development Sun, 19 Mar 2023 08:47:30 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 PHP : require_once | Core function https://priyank.rocks/php-require_once-core-function/ Sun, 19 Mar 2023 08:47:16 +0000 https://priyank.rocks/?p=9421 I just want to log one pitfall here that I believe every developer must know.

require_once if we have it across different folders which include the same file, then we expect that it should only load once. But you might get an error saying cannot redeclare the trait again or the trait is already defined.

The key thing here is that require_once requires a full absolute path, then you can expect require_once to load it only once. I had files access from different folder levels and this solved the issue for me.

Maybe for files required at the same folder level, this may not be an issue, haven’t tested that yet.

]]>