I'm working in a team on a e-shop website.
Recently, we've passed on Debian Jessie and from php5.4 to 5.6
Since then, we have multiple bug with require and require_once
Here's a file that raise an ERROR 500
<?php
require('/data/vhosts/mycompany.com/public_html/mp/../includes/functions/marketplace_tools.php');
//print_r(get_included_files());
require_once('/data/vhosts/mycompany.com/public_html/mp/../includes/functions/marketplace_tools.php');
echo 'pouet';
?>
The error.log say this :
PHP Fatal error: Cannot redeclare match_marketplace_products() in Cannot redeclare match_marketplace_products() on line 1
The filepath is good.
Marketplace_tools.php don't have require/include in
Marketplace_tools.php is just a bunch of function we use
If I run this file in command line, it works well
If I uncomment the print_r, it does not raise ERROR 500
This bug randomly appear and disapear
Cannot redeclare match_marketplace_products()
This error message tells you that there is a function name (match_marketplace_products) in the file you're including that already exists in the current PHP program.
You're using require_once(), but check that you haven't pulled in the same file elsewhere using require() (or include()).
Also check that the function name match_marketplace_products is only defined in this one file -- if it's defined in another file that is also included, then this will cause this error.
Related
I have a directory full of test files with many tests in each test file. I added a new test file and from the command line "./phpunit-8.5.5.phar SupportTest.php" results in success for all tests within that file. When I want to run all of the tests with "./phpunit-8.5.5.phar ." I get an error regarding a global variable what appears to be a pre-load stage of PHPUnit (because none of the tests had run yet):
PHP Notice: Undefined variable: myGlobalVariable in /Path/To/Tests/SupportTest.php on line 36
[tests would then run here, but I added an "exit" in the SupportTest.php file if the variable was not set so that I could debug this issue]
The variable "$myGlobalVariable" is set in a file that is included in SupportTest.php via 'require_once("../globals.inc");' If I check "isset($myGlobalVariable)", then it is NOT set when running all tests (.) but IS set when running the single test file (SupportTest.php). If I modify the code to "require" instead of "require_once" then that fails because the full directory test run already included "globals.inc" and a global function was already defined, so it fails on that:
PHP Fatal error: Cannot redeclare globalFunction() (previously declared...)
Is there some strange memory limit happening due to the addition of this one file? Why would PHPUnit lose the global variables yet believe it has included all of the global settings file (globals.inc)? There are a total of 504 tests spread across about 39 files.
Using Homebrew PHP 7.4, PHPUnit 8.5.5 (tried 8.5.22 with same failure)
Please excuse an, at least initially, high level question about logging php script errors. Is it a valid expectation that php error_log will record errors in a class file that is in a different directory to the main php script?
I have two php files
pages/add_edit_xxxx.php
and
class/class_xxxx.php
add_edit_xxxx.php depends on public functions in the class file
If I deliberately introduce an error in pages/add_edit_xxxx.php then pages/error_log correctly records the line number of the error
If I deliberately introduce an error in class/class_xxxx.php then class/error_log sometimes records the error and sometimes remains unchanged
I do not have access to php.ini
But I guess that the settings are OK as sometimes class/error_log records the error but more often than not it does not log the error.
I have this in a settings file:
ini_set("include_path", '/home/xxxx/php:' . ini_get("include_path") );
error_reporting(E_ERROR);
#session_start();
Called at the start of pages/add_edit_xxxx.php
include_once("settings.php");
I hope this is enough to enable thoughts on whether it is a valid expectation that the errors in the class file should be reliably caught and logged. At the moment I cannot recreate a scenario when a log was created - but this is an example of class/error_log entry that was written yesterday
[20-Oct-2021 19:00:48 UTC] PHP Parse error: syntax error, unexpected '$tempRS' (T_VARIABLE) in /home/xxxxx/public_html/xxxxx.com/class/class_xxxx.php on line 36
If I remove the deliberately inserted errors (for example a missing semi-colon) then the page functions well.
Thank you
resolved by updating this line in the settings file:
error_reporting(E_ERROR);
to
error_reporting(E_ALL);
I'm getting this error when my site is online
[host www.sitename.com] Backend fatal error: PHP Fatal error: require_once() [function.require]: Failed opening required 'admin/config/connection.php' (include_path='.:/opt/cpanel/ea-php53/root/usr/share/pear:/opt/cpanel/ea-php53/root/usr/share/php') in /home/mistrybu/public_html/index.php on line 373\n
The site works well in localhost but when its put online , the dynamic part is not showing.
I changed the php version from php7 to php5 in cpanel. Now the front end is working but the backend is not.
Can someone help me solve this error?
PHP version
Definitely do not go back to PHP5. Keep it to 7. If that means rewriting some of the existing code, so be it, it will make your site more secure and more future proof.
Error Message
Your require_once() method cannot find or access a particular file. This is most probably because:
File missing
The file (connection.php) doesn't exist in the given location (admin/config). Now keep in mind that as the location doesn't start with a /, it's going to be relative to where the require_once() method is being run from.
Since you're running require_once() from:
home/mistrybu/public_html/
it's going to look for the file here:
/home/mistrybu/public_html/admin/config/.
Does that location exist? Does the connection.php reside in the folder?
Folder mismatch
Try adding the following prefix to your path, and see if that makes a difference:
require_once $_SERVER['DOCUMENT_ROOT'].'/admin/config/connection.php';
File errors
Maybe the file exists, but for some reason, gives an error. Try running the following from your command line and see if you get any errors:
php -f admin/config/connection.php
someone could tell me if there is a reason why I get these PHP errors, which should not exist.
PHP Warning: include (xyz.php): failed to open stream: No such file or directory in /mypath/myfile.php on line 351
When the file clearly exists!
PHP Fatal error: Can not access MyClass::$myproperty in /mypath/MyClass.php on line 250
When the declaration exists:
class MyClass
{
...
public static $myproperty = array();
...
I would like to emphasize that these errors are not always reported! But only once in a while. When I make a mistake writing a part of the code, the PHP fatal error should always occur, not 5 times a day from 12:22 to 12:27 and nevermore. I'm talking about a site from thousands of visits a day, I'm also talking about a .php file that is included on a regular basis in every request of any page.
I can't get any error in my pc (php 5.6 also) when I run and test the web application.
Is it possible some server problem?
Thanks.
Recently I met a weird error and hope someone can help.
We use LiteSpeed WebServer and Nginx on top, with PHP 7.5 and MySQL 5 (well, WordPress is the framework). It runs well for many days.
Suddenly it goes fatal at this line in different files
include ("class-xxx.php");
The error log says
[02-Oct-2018 13:04:36 UTC] PHP Fatal error: require(): Failed opening required 'dlass-xxx.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear') in /xxx.php on line N
I double checked the code and see that the file name is declared "class-xxx.php", but somehow the server tries to include "dlass-xxx.php", thus it cannot find the file and trigger fatal error.
Solution? I re-upload the file, it works. But then it goes fatal in another file, at similar lines using include.
I notice that the first character in the file name, for example "c", is read incorrectly and shift 1 byte before (or after), so the file name is correct.
Such as
include "class-xxx.php" is parsed/read as "dclass-xxx.php"
include "page-xxx.php" is parsed"read as "opage-xxx.php"
...
this is very strange. Do anybody know the reason? Is it related to any caching/memory management of LiteSpeed or Nginx or PHP 7. ?
It happens on PHP 7. only because if I switch to PHP 5.6, the error does not happen.
Hope someone can help. Thanks a lot.