I am puzzled by this. I get a PHP error for redeclaring a function although the function is only declared once. The code looks as follows:
function array_search_partial($arr, $keyword) {
foreach($arr as $index => $string) {
if (strpos($string, $keyword) !== FALSE)
return $index;
}
}
$has_cv = array_search_partial($fnames,'cv:');
In my log files this produces the following error (the page does not complete loading):
[31-Jan-2020 10:48:32 Europe/Berlin] PHP Fatal error: Cannot redeclare array_search_partial() (previously declared in /XXX/XXX/XXX.php:332) in /XXX/XXX/XXX.php on line 332
So the error occurs on line 332 because the function has already been declared on line 332?!? Just to make sure I renamed the function to something arbitrary and I get the same error. Does anyone know what could be going on here?
I try to used to an old customized module in my Prestashop that runs with php 7.0.
I got an error and no idea...
Fatal error: Uncaught Error: Call to undefined method Product::getFrontFeaturesHiddenByNameStatic()
And here is the line of code.
$feature = Product::getFrontFeaturesHiddenByNameStatic((int)($params['cookie']->id_lang), $product['id_product'],'_Descriptif accueil');
And that function is defined in "override" folder.
public static function getFrontFeaturesHiddenByNameStatic($id_lang, $id_product, $featureName) {
self::getFrontFeaturesStatic($id_lang, $id_product);
if( isset(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang]) )
foreach(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang] as $feature) {
if( $featureName == $feature["name"] )
return $feature;
}
return null; // nothing has been found
}
Thanks in advance !
I think I found the solution.
Actually the override definition was not in the right folder.
It was in override/classes and failed, while set in modules/mymodule/override/classes, it seems to work fine...
Thank for your help!
I'm quite new to php and I tested this code on my local server and it was working fine but when I uploaded it to webserver I started getting the following errors.
This is the Code :
"if($stmt=$mysqli->prepare("SELECT members.id, permissions.name FROM members,permissions WHERE username=? AND password=? AND members.type=permissions.id" )){
$username=$input["user"];
$password=$input["pass"];
$configsalt=$config["salt"];
$stmt->bind_param("ss",$username,md5($password.$configsalt));
$stmt->execute();
$stmt->bind_result($id,$type);
$stmt->fetch();"
The line 39 is "$stmt->bind_param("ss",$username,md5($password.$configsalt));"
Strict Standards: Only variables should be passed by reference in
/home/hotel132/public_html/bulbmg/index.php on line 39
Fatal error: Cannot redeclare is_admin() (previously declared in /home/hotel132/public_html/bulbmg/includes/config.php:22) in /home/hotel132/public_html/bulbmg/includes/config.php on line 28
I don't know why the second error is occuring!!!
'
.......
//Functions
function is_admin(){
if($_SESSION['type']=="admin"){
return true;
}
else{
return false;
}
} //line 28
?>'
Kidly help me out with this.
You should not use literals, try using variables.
The error:
Are you including or requiring file(s) more than one time? Try include_once/require_once
Otherwise check function_exists
EDIT:
Have you tried this?
if (!function_exists('is_admin')) {
function is_admin(){
if($_SESSION['type']=="admin")
return true;
else
return false;
}
}
After updating our server to PHP 5.4 and a Drupal site to Drupal 6.37 I keep getting this error message and I am not able to get past it
Fatal error: Call to undefined function drupal_get_path() in /home/mysite/public_html/includes/module.inc on line 285
this is the related function call
function module_load_include($type, $module, $name = NULL) {
if (empty($name)) {
$name = $module;
}
$file = './'. drupal_get_path('module', $module) ."/$name.$type";
if (is_file($file)) {
require_once $file;
}
else {
return FALSE;
}
}
Even when I try to run update.php I still get the same error
I am new to Drupal so any help will be greatly appreciated
Please let me know what additional info you may need since it is my first post here and as I said I don't know much about Drupal
hey guys was hoping you could help me out..
just to let u know in advance, im a relatively new php coder, doing a practice project, and came across this problem and ive spent like an hour of rechecking and googling but just cant figure out whats causing it
error: Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\forum\classes\ClassUser.php on line 7
the segment of the code causing the problem:
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
Class User{
__construct($u,$p){ //this is line 7
$user=$u;
if(strlen($p)>30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
$password=0;
}
else{
$password=hash_hmac('md5',$p,KEY);
}
}
oh and since im new to php, incase im doing something which i should not be, please to recommend.. thanks in advance.
note:ive removed the php tags since they seemed to be messing with the formatting of this post :/
note2: im also getting another notice
Notice: Use of undefined constant KEY - assumed 'KEY' in C:\wamp\www\forum\classes\general.inc on line 20
but im assuming thats more of a warning than an error... but just adding incase it has something to do with the error
general.inc:
//error definations
define("ERROR_FIELD_EMPTY","Error! All required fields not filled");
define("ERROR_INVALID_SIGNIN","Error! Username/password do not match!");
define("ERROR_GENERAL_INPUT", "Error! Invalid input given");
define("ERROR_SQL_CONNECT","Error! Could not connect to sql database");
//field sizes
define("PASSWORD_LENGTH",12);
define("USERNAME_LENGTH",30);
//sql server details
define("SQL_SERVER_NAME","localhost");
define("SQL_SERVER_USERNAME","root");
define("SQL_SERVER_PASSWORD","");
define("SQL_SERVER_DATABASE","forums");
define(KEY,"key");
function __autoload($className){
require_once($_SERVER["DOCUMENT_ROOT"]."forum/classes/Class$className.php");
}
ClassUser.php
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
Class User{
__construct($u,$p){
$user=$u;
if(strlen($p)>30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
$password=0;
}
else{
$password=hash_hmac('md5',$p,KEY);
}
}
public function validate(){
if(strlen($user)>30|| empty($user) || preg_match('/[^a-zA-Z0-9]/i',$password==0 )){
throw new Exception(ERROR_GENERAL_INPUT);
}
$user=mysql_real_escape_string($user);
return true;
}
public function insert(){
// this->validate();
$conn= mysqli_connect(SQL_SERVER_NAME,SQL_SERVER_USERNAME,SQL_SERVER_PASSWORD,SQL_SERVER_DATABASE);
if(empty($conn)){
throw new Exception(ERROR_SQL_CONNECT);
}
$query="INSERT into USERS VALUES ($user,$password)";
$conn->query($query);
}
private $user;
private $password;
};
NewUser.php
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
try{
$user = new User($_POST['UserName'],$_POST['Password']);
$user->insert();
}
catch(Exception $Error){
echo $Error->getMessage();
}
Your __construct needs to have the word function in front of it, or better yet public function, in the same way as the other methods in the class (ie validate and insert in your case).
ie you need the following:
public function __construct($u,$p){ //this is line 7
Change the line to:
public function __construct($u, $p) {