PHP UndefinedFunctionException in simply OR comparison - php

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?

Related

How to reference a Class Method using an array variable in PHP7?

I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();

Yii - Fatal error: Cannot redeclare function

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?

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

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