'Upgrade to PHP 7.4 now throwing "Uncaught Error: Class 'Page' not found"
Our client is slowly updating some really dated PHP web apps to 7.4, and I have brought them into a Docker test container as I debug and update a lot of the depreciated code. We have an order portal, and the index page looks like this:
<?PHP
define("TRACKER", "1");
require "includes/config.php";
$page = new Page;
$page->show_page();
?>
That is how it was originally written, and works on the current dated server.
So when I upgraded, it started throwing this error:
PHP Fatal error: Uncaught Error: Class 'Page' not found in /var/www/html/orders/index.php:9\nStack trace:\n#0 {main}\n
Mind you, what's even more off is that we have a sister web app running in the same container, and that app's index page is written exactly the same, yet working.
For context, the file structure of our test container has 3 apps:
container/webapp1
container/webapp2
container/orders
index.php for the Order Portal is directly in orders/
Page.php is in orders/classes/
config.php is in orders/includes/
Is the "require" line depreciated? Does the Page.php file now need to be explicitly stated with PHP 7.4?
I am not the original author of this, and not an expert, so I'm admittedly bandaiding it as I go.
I also checked for depreciated code in Page.php, and found a silly line that was invalid. I quickly fixed that, and it still did not fix anything. Oh, and config.php also wasn't throwing any errors, and theoretically works.
I am not a PHP wizard, and would love some wisdom on what changed between PHP 5 vs 7.
Thanks!
EDIT: A clue may be the defined paths in my config being depreciated
Progman below asked if Page.php is being included in index.php, but it isn't.
Instead it looks like the entire directory for classes is being defined:
define("CLASS_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/classes/");
Solution 1:[1]
The answer to this question was really silly: The PHP short-tags. Changing to 7.4 broke all of the short tags, throwing all sorts of vague errors about undefined classes.
Changing from <? to <?PHP fixed the bug specified in this post.
However, there was a ton of valuable information on updating depreciated functions. In my case, __autoload was depreciated.
Additionally, _destruct() is depreciated, but I need to find a replacement or alternative to the function in my web app.
Thanks everyone for the help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Powermaster Prime |
