This question already has answers here:
PHP error - cannot redeclare function [duplicate]
(5 answers)
Closed 9 years ago.
After I have instaled in my site one script, I have an error:
Fatal error: Cannot redeclare ae_detect_ie() (previously declared in /home/xdesign/public_html/Powerful/config.php:24) in /home/xdesign/public_html/Powerful/config.php on line 29
This is the line:
function ae_detect_ie()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}
I don't understand what I did wrong!
The site: http://fbswapes.com
The same script is working in another host.
Simpily you have declared a function twice.. Example:
Global.Fun.php
<?php
function Do_Something (){
echo "This Does Something";
}
?>
Index.php
<?php
include "Global.Fun.php";
function Do_Something($Arg){
echo "Argument Supplied".$Arg;
}
?>
Notice, I have declared the same function twice, one in my global.fun.php page and again in the index.php page..
If you are in doubt that a function is currently set:
if (function_exists('Do_Something')){
echo "Function Exists";
}else{
echo "Function Not Found, This name Can be used!";
}
Related
I have this file structure in my php project:
splitted.php (ERROR)
<?php
require_once "include1.php";
require_once "include2.php";
include1.php
<?php
a();
include2.php
<?php
function a(){ echo "success"; }
It will gives error Uncaught Error: Call to undefined function a().
But if we combined them with the same exact sequence, it doesnt gives error.
combined.php (SUCCESS)
<?php
a();
function a(){ echo "success"; }
Why it gives error when we splitted the code but run without issue when we combine it? How to fix this error without altering the structure and the sequence of the file?
I am trying to update one of the sites I maintain to the latest PHP and during this, I have come across the following error:
Fatal error: Call to undefined function tep_session_name() in ... /includes/application_top.php on line 83
The code it is referring to is:
// set the session name and save path
tep_session_name('osCAdminID');
tep_session_save_path(SESSION_WRITE_DIRECTORY);
But I have looked at the sessions.php file are the function is defined in the below code:
function tep_session_name($name = '') {
if ($name != '') {
return session_name($name);
} else {
return session_name();
}
}
Any help in identifying the cause would be greatly appreciated.
Thanks, E.
I'm absolutely sure, that you call this function before you include file with function declaration
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 7 years ago.
Fatal error: Cannot redeclare getIp() (previously declared in C:\xampp\htdocs\ecommerce\functions\functions.php:12) in C:\xampp\htdocs\ecommerce\functions\functions.php on line 21
This is the error I received when creating a checkout page
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
this is the function it refers to
<?php
if(!isset($_SESSION['customer_email'])) {
include("customer_login.php");
}else{
include("payment.php");
}
?>
and it happens after this is not set function
probably you have included the file before, use include_once
<?php
if(!isset($_SESSION['customer_email'])) {
include_once("customer_login.php");
}else{
include_once("payment.php");
}
?>
or you can check if function exists with function_exists:
if(!function_exists("getIp")) {
// declare your function
} else {
// it already exists, do something else
}
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm getting an error as:
Parse error: syntax error, unexpected end of file in ...\system\core\Loader.php(829) : eval()'d code on line 307..
this is code in loader.php
foreach ($this->_ci_model_paths as $mod_path)
{
if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
{
continue;
}
if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
{
if ($db_conn === TRUE)
{
$db_conn = '';
}
$CI->load->database($db_conn, FALSE, TRUE);
}
if ( ! class_exists('CI_Model'))
{
load_class('Model', 'core');
}
require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model);
$CI->$name = new $model();
$this->_ci_models[] = $name;
return;
} // this line number 307
and eval code
if ((bool) #ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
{
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));//this is line number 829
}
else
{
include($_ci_path);
}
I tried searching for this but couldn't find anything.
This will be caused by a File you have written.
It looks like you might be loading a model with a missing { or } or some syntax error. So you need to determine what models you are loading.
You can do that from the URL to see what controller/method you are calling. Check the controllers constructor to see if you are loading any models there... Check the Method and also check your autoloader.
Then check those models - the ones you have written - and look for errors. If you are using a decent editor or IDE, you should see where they are occurring.
This is a demo code in the line 6 there is a function find() actually this function doesn't exist and when i run this file I got error Fatal error: Call to undefined function find() in C:\xampp18\htdocs\demo\exp.php on line 6
my question is that is this possible in PHP to handle this type error i.e. want to print Line 2: 5 which is after the first if block. thanks in advance.
<?php
$a=10;
if(true)
{
echo "Line 1: ".$a/find();
}
if (true)
{
$b=2;
echo "<br>Line 2: ".$a/$b;
}
?>
that's not good idea. what about check whether find() is exist or not using function_exists. example:
<?php
$a=10;
if(true) {
echo "Line 1: " . (function_exists('find') ? $a/find() : $a);
}
if (true) {
$b=2;
echo "<br>Line 2: ".$a/$b;
}
?>