0

I am trying to call a function printRightContent present in **root_directory/lib/common.php ** in Adcovate.php but it gives me the following error error:

PHP Fatal error: Uncaught Error: Call to undefined function printRightContent()

This is my PHP file Adcovate.php:

<?php
include 'lib/common.php';
function printResults($page, $perpage)
{
?>
<div id="right_content">
        <?php
        error_reporting(E_ALL);
        ini_set('log_errors', 1);
        ini_set('error_log', 'hey_this_errors.log');
        printRightContent();
        ?>
    </div>
<?php
}
?>

common.php:

<?php 
/* Optimize site using GZIP Compression also see .htaccess */
echo "<script>console.log('Common library checkpoint#1' );</script>";
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
<?php
/* dirty code */
define("WEBNAME", "Lawyers.com");
function printRightContent()
{
  echo "<script>console.log('Common library checkpoint#2' );</script>";
  -------somework-----
}?>

I have also tried this link : PHP Fatal error: Call to undefined function?

But when I am implementing changes from this link it gives me error:

crbug/1173575, non-JS module files deprecated.

I have tried using adding logs in console using this way: echo "console.log('Common library checkpoint#1' );";

I am also creating the log file using this way:

error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('error_log', 'hey_this_errors.log');

1 Answers1

0

I advise you to move

error_reporting(E_ALL);
ini_set('log_errors', 1);
ini_set('error_log', 'hey_this_errors.log');

at the top of Adcovate.php and use

require 'lib/common.php';

instead of

include 'lib/common.php';

to verify if common.php is really included

Pippo
  • 2,173
  • 2
  • 3
  • 16
  • ``` [16-Mar-2023 23:49:14 UTC] PHP Warning: Undefined array key "country" in Advocate.php [16-Mar-2023 23:49:14 UTC] PHP Warning: Undefined array key "cat_id" in Advocate.php [16-Mar-2023 23:49:14 UTC] PHP Warning: Undefined array key "cid" in Advocate.php [16-Mar-2023 23:49:14 UTC] PHP Fatal error: Uncaught Error: Call to undefined function printRightContent() in Advocate.php Stack trace: #0 Advocate.php .php(293): printResults() #1 {main} thrown in Advocate.php .php on line 528 ``` – Anirudh Rawat Mar 17 '23 at 00:03
  • It seems that *common.php* is included because you don't have any error about it. Now we have to make sure that we are including the right *common.php*: I suggest you to add at the top of *common.php* in the next row of * – Pippo Mar 17 '23 at 00:59
  • yes it is printing TADAAAAAH I guess there is something wrong with the function. – Anirudh Rawat Mar 17 '23 at 01:53
  • 1
    I'm using same method to debug the issue by placing ```die('TADAAAAAH'); ``` inside the function and realized that function is not being called properly although the spelling matches – Anirudh Rawat Mar 17 '23 at 02:14
  • In PHP a function can be conditionally defined wrapping it in an if statement: check if you have omitted something like a semicolon or some other thing that force the function not to be defined (i've seen that you open and close * – Pippo Mar 17 '23 at 02:19