Call to undefined method Memcached::getAllKeys() on PHP7 - php

I have this script
$prefix = "feed_";
$keys = #$memcached->getAllKeys();
foreach ($keys as $index => $key) {
if (strpos($key,$prefix) !== 0) {
unset($keys[$index]);
} else {
$memcached->delete($key);
}
}
that return this fatal error: Fatal error: Uncaught Error: Call to undefined method stdClass::getAllKeys().
If I run PHP5.* all works fine. But with PHP7.* it's not the same.
I don't find anything about deprecated function http://php.net/manual/en/memcached.getallkeys.php
How can I resolve this problem?

Related

PHP Recoverable fatal error - Catch not working

I have code that I am trying to update to work with at least PHP version 7.3 and even when I put in a try catch statement I still get a fatal error thrown.
Below is the function that puts Objects into the Session. line causing error: $objects[$i] = $Object;
function findObjectsLIB() {
$objects = ""; $i = 0;
foreach ($_SESSION['Objects'] as $o => $Object) {
$className = get_class($Object);
if (!empty($className)) {
try {
$objects[$i] = $Object;
$i++;
} catch(Exception $err) {
$_SESSION['errors'] .= $err->getMessage();
}
}
}
return $objects;
}
I am getting this error.
PHP Recoverable fatal error: Object of class Extra could not be
converted to string.
How it not being caught?
For one it is strange that it is not being caught and why is it having an issue in 7.3 but not 5.6?

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?

Fatal error: Cannot use object of type Closure as array

I have this snippet of code that seems to break my site when I update a particular plugin. The plugin I updated appears to being closures some where because I get the error:
Fatal error: Cannot use object of type Closure as array.
The error traces back to this code:
if (!empty($wp_filter['admin_menu'])) {
foreach($wp_filter['admin_menu'] as $cb) {
foreach ($cb as $k => $v) {
if (
isset($v['function'])
&& is_a($v['function'][0],'Ma_Settings_PN')
&& isset($v['function'][1])
&& 'add_menu_item_push_notifications' == $v['function'][1]
) {
remove_action('admin_menu',$k);
}
}
}
}
From what I gather this code is used to remove an action from a particular class somewhere else. What is the best way to get rid of this Fatal error?

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