create_function() error in badwordsfitler_npm [duplicate] - php

This question already has answers here:
PHP 7.2 Function create_function() is deprecated
(6 answers)
Upgrading from create_function to closures
(1 answer)
Closed 5 months ago.
Hello, everyone.
I am using badwords-filter npm and it is using create_function().
But as you know that function is removed from php 8.
So it is getting error now and I can't sure how to fix it.
If you are familiar with it, please help me.
private function flattenArray($array)
{
$objTmp = (object)['aFlat' => []];
array_walk_recursive($array, create_function('&$v, $k, &$t', '$t->aFlat[] = $v;'), $objTmp);
return $objTmp->aFlat;
}
On the above code, the create_function() is getting error.

Related

how can i used other function instead of each() function is deprecated? [duplicate]

This question already has answers here:
How can I update code that uses the deprecated each() function?
(12 answers)
Closed 7 months ago.
here I share my old code need with each function so now I got this kind of error
each() function is deprecated
my code is
list($k, $v) = each($files);
You can use foreach statement like :
<?php
foreach($files as $k => $v) {
// Do some stuffs
}
Foreach works since PHP 4.

PHP Function create_function() is deprecated , the code cant work in newest PHP? [duplicate]

This question already has answers here:
PHP 7.2 Function create_function() is deprecated
(6 answers)
Closed 1 year ago.
I have a function which im not entirely sure how to convert it to get working in newest php
$eventSponsor = array_map(create_function('$o', 'return $o["id"];'), $event->sponsors);
which method should i use in newest php version ?
yeah i was searching and i found this method called anonymous function so the code be like
$awe function ($o) {
return $o["id"];
};
$eventSponsor = array_map($awe,$event->sponsors); ```

PHP 7.3 Function create_function() deprecated from 5.6 update [duplicate]

This question already has answers here:
PHP 7.2 Function create_function() is deprecated
(6 answers)
Closed 2 years ago.
I have recently upgraded a site im working on from PHP Version 5.6 to 7.3
The problem I am having is with a deprecated function in my wordpress functions.php
add_filter('max_srcset_image_width', create_function('', 'return 1;'));
How would i rewrite the above code for 7.3
I have already tried:
add_filter('max_srcset_image_width', function('', 'return 1;'));
Thanks
You can use functions directly like closures.
add_filter('max_srcset_image_width', function() { return 1; });
Update:
Since PHP 7.4 you can use shorthand arrow functions and write it shorter.
add_filter('max_srcset_image_width', fn() => 1);

The each() function is deprecated. This message will be suppressed on further calls PHP 7.2 [duplicate]

This question already has answers here:
How can I update code that uses the deprecated each() function?
(12 answers)
Closed 4 years ago.
I have the below each() line in a PHP file on a server where I recently upgraded the PHP version from 5 to 7.
while(list($file, $info) = each($this->images))
The error below is thrown by the web server after the restart.
The each() function is deprecated. This message will be suppressed on further calls
What will be the correct way of re-writing the above line of code in PHP 7.2?
Thank you.
You should be able to swap out your each for a foreach in the most part.
<?php
foreach($this->images as $file => $info) {
// ...
}

Unexpected T_FUNCTION for function on PHP 5.2 [duplicate]

This question already has an answer here:
Making anonymous functions from PHP 5.3 work with PHP 5.2
(1 answer)
Closed 8 years ago.
I'm using the following function:
function uniqueACF(array $array) {
$flatten = array();
array_walk_recursive($array, function($value) use(&$flatten) {
$flatten[] = $value;
});
$flatten = array_unique($flatten);
return $flatten;
}
This works fine in PHP 5.3, but for PHP 5.2 it will give a 'unexpected T_Funcion for the array_walk_recursive line. It probably has to do with the function($value) or use(&$flatten).
But I'm not sure how I should make this work on PHP 5.2. How should I rewrite this for PHP 5.2?
Anonymous functions are available from PHP 5.3. That's why it doesn't work in PHP 5.2.
You should really think, why you move to PHP 5.2 - even PHP 5.3 reached already end of life and PHP 5.6 will be released soon.

Categories