Yii - Fatal error: Cannot redeclare function - php

I have this function called checkCentre1() and I'm unable to open my web application due to below error appearing:
Fatal error: Cannot redeclare checkCentre1() (previously declared in C:\xampp\htdocs\scms2\protected\views\layouts\main.php:39) in C:\xampp\htdocs\scms2\protected\views\layouts\main.php on line 50
I did not declare checkCentre1() somewhere else. I have tried few solutions below but none is working:
if (!function_exists('checkCentre1')) { //function code }
include_once
My code is as below:
function checkCentre1($value){ //line 39
$modelUser = AuthUsers::model()->findByPk($value);
if($modelUser){
if($modelUser->ref_user_type_idref_user_type == 1 || $modelUser->ref_user_type_idref_user_type == 2){
return true;
}else{
return false;
}
} else
return false;
} //line 50
Does anybody has any other solution for this?

Related

PHP Fatal PHP Fatal error: __clone method called on non-object

So, I am working on a project and I am having an issue as I keep getting both errors and warnings. I am quite new to PHP so be gentle. The program runs fine using PHP 5.5 However when I run the program in PHP 5.6 I receive several errors as follows;
[10-Oct-2016 10:04:46 America/Denver] PHP Warning: Erroneous data format for unserializing 'MMR\Bundle\CodeTyperBundle\Entity\User' in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833
[10-Oct-2016 10:04:46 America/Denver] PHP Notice: unserialize(): Error at offset 49 of 50 bytes in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833
[10-Oct-2016 10:04:46 America/Denver] PHP Fatal error: __clone method called on non-object in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 837
Project Info
Platform: Symfony
PHP Version: 5.6
Affected Code
public function newInstance()
{
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); //Line 833
}
}
return clone $this->_prototype; //Line 837
}
Any help would be greatly appreciated
I tested:
var_dump(clone $t=unserialize(sprintf('O:%d:"%s":0:{}', strlen('name'), 'name')));
And it works.
You have to check the value of $this->name maybe its empty or has illegal chars.
Where is $this->name set in the first place?
Quick Fix:
just add one more version i.e: PHP 5.6 for your if condition and it will be PHP_VERSION_ID === 50640 in your if condition
like:
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID === 50640) {
$this->_prototype = $this->reflClass>newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
}
}

Fatal error: Call to undefined function tep_session_name()

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

PHP UndefinedFunctionException in simply OR comparison

I am working on a custom web shop project. Currently I am experiencing a strange error when using one of my classes:
namespace Services\MyServices;
class MyAppService {
protected function someMethod($transfer_id) {
...
$hash1 = sha1($someValue1);
$hash2 = sha1($someValue2);
$hash3 = sha1($someValue3);
// The following code is in line 144
$checkHash = (($hash1 == $transfer_id) || ($hash2 == $transfer_id) || ($hash3 == $transfer_id));
...
}
}
Fatal Error: Call to undefined function Services\MyAppService\ ()
Uncaught PHP Exception UndefinedFunctionException: "Attempted to call function " " from namespace "Services\MyAppService"." at /webspace/..../Services/MyAppService/MyAppService.php line 144
So line 144 is just a simple OR comparison, isn't it? What could be the problem here?

Strict Standards: Only variables should be passed by reference

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;
}
}

Fatal error: Call to a member function toOptionArray() on a non-object in /Mage/Adminhtml/Block/System/Config/Form.php on line 463

After I run compilation and enable it, flush cache and go to "System -> Configuration" I get the following error
Fatal error: Call to a member function toOptionArray() on a non-object in mysite/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 463
If i turn off enable flush cache and go back to configuration it works.
I tried the solution in Fatal error: Call to a member function toOptionArray() on a non-object in mysite/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 463
But that didnt work
Go to app\code\core\Mage\Adminhtml\Block\System\Config\Form.php
find the following on line 463
$optionArray = $sourceModel->toOptionArray($fieldType == ‘multiselect’);
and replace it with:
if(is_object($sourceModel)){
$optionArray = $sourceModel->toOptionArray($fieldType == ‘multiselect’);
} else {
Mage::log($e->source_model);
}
I want to be able to enable compilation and access configuration.
Thanks in advance for your help.
Replace the code with
if ($e->source_model) {
$sourceModel = Mage::getSingleton((string)$e->source_model);
if ($sourceModel instanceof Varien_Object) {
$sourceModel->setPath($path);
}
if(is_object($sourceModel)){
$field->setValues($sourceModel->toOptionArray($fieldType == 'multiselect'));
} else {
Mage::log($e->source_model);
}
}
http://indianicorange.wordpress.com/2010/10/04/fatal-error-call-to-a-member-function-tooptionarray-on-a-non-object/

Categories