0

Fatal error: Cannot redeclare encrypt() (previously declared in /var/www/html/Medapps_UAT/data/config.inc.php:136)

Included config.inc.php using require_once

emp_details.php

<?php
ini_set("soap.wsdl_cache_enabled", "0");
require('lib/nusoap.php');
require('lib/nusoapmime.php');
require_once("../data/config.inc.php");
require_once("../tax_calculation.php");
.
.
.
?>

tax_calculation.php

<?php
 require_once("data/config.inc.php");
?>

as i have used only require_once , but getting function redeclared .

php version 5.1.6.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
sridhard
  • 119
  • 3
  • 15

2 Answers2

1

It's because PHP see's ../data/config.inc.php and data/config.inc.php as different files. It doesn't know it's already included it because the file path is different.

You have a couple of options;

You can use realpath() to return the whole path to the file;

require_once(realpath('../data/config.inc.php'));

Or, you could use the DOCUMENT_ROOT property in $_SERVER.

require_once($_SERVER['DOCUMENT_ROOT'] . 'data/config.inc.php');

This should ensure these files are loaded only once.

Tom
  • 4,257
  • 6
  • 33
  • 49
  • actually config.inc.php present in project_name/data/config.inc.php . emp_details.php file present in project_name/api/emp_details.php se we use .. to include config.inc.php – sridhard Feb 28 '17 at 11:58
0

Make sure you didn't declare the function in the same name "encrypt" in any of the included file such as 'lib/nusoap.php', 'lib/nusoapmime.php' or in your current file 'tax_calculation.php'.

If you are using any IDE like net-beans or eclipse, just import the project in the IDE and search for the function name. You can easily find the total occurrence. Then rename the function name and check.

  • encrypt() function is used only file in config.inc.php – sridhard Feb 28 '17 at 11:44
  • Try hiding the line require_once("../data/config.inc.php"); in emp_details.php and check. – Karthikeyani Srijish Feb 28 '17 at 11:46
  • it works after comment in emp_details.php . but i was unable to access the functions inside config.inc.php using object **sample code** `class tax_calculaction { public function __construct(){ $this->connection=new database() }` execution stops in constructor – sridhard Feb 28 '17 at 12:06