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

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

Related

I get a "PHP Fatal error: Cannot redeclare function" although I only have the function once

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?

Non-static method should not be called statically in Kohana 2.3.4

i've moved my Kohana 2.3.4 installation to a new hosting with php7 (probably that's a root of the issue) and now i am getting the following error:
Uncaught PHP Error: Non-static method AdminHook::menu_tree() should not be called statically in file system/core/Event.php on line 209
Here's my Event.php around line 209 (call_user_func($callback); is at line 209):
public static function run($name, & $data = NULL)
{
if ( ! empty(self::$events[$name]))
{
// So callbacks can access Event::$data
self::$data =& $data;
$callbacks = self::get($name);
foreach ($callbacks as $callback)
{
call_user_func($callback); // LINE 209
}
// Do this to prevent data from getting 'stuck'
$clear_data = '';
self::$data =& $clear_data;
}
// The event has been run!
self::$has_run[$name] = $name;
}
And here's the AdminHook class:
class AdminHook {
public function menu_tree(){
$session = Session::instance();
if(isset($_GET['_ml']) AND $_GET['_ml'] == 1) {
$session->set('menuLink', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//url::redirect(url::current());
}
global $menuLink;
$menuLink = $session->get('menuLink');
}
}
If i set menu_tree function to static, i get the following error:
Uncaught PHP Error: Declaration of Menu_Model::validate(array &$array, $save = false) should be compatible with ORM_Core::validate(Validation $array, $save = false) in file application/models/menu.php on line 18
I've been trying to find a solution for the next couple of days, but can't seem to find one. Any help is highly appreciated!
Errors are not related to each other. By simply setting that method as static, php goes to showing the next error.
You have bad Menu_Model declaration. It mut be compatible with ORM_Core::validate
Menu_Model::validate(/*bad: array & */ Validation $array, $save = false)

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 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?

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