Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Migration script PunBB php 7.1 =c3=a0 php 7.2 : fonction create=5ffunction()

5 réponses
Avatar
Pierre www.aribaut.com
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?
--
http://zetrader.info & http://zetrader.fr
http://aribaut.com - http://zeforums.com

5 réponses

Avatar
Otomatic
"Pierre www.aribaut.com" écrivait :
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?

La meilleure manière de trouver une réponse ne serait-il pas d'aller
voir la documentation PHP ?
Par exemple :
http://php.net/manual/fr/function.create-function.php
puis ce qui est préconisé en remplacement :
http://php.net/manual/fr/functions.anonymous.php
Migration de PHP 7.1 vers 7.2
http://php.net/manual/fr/migration72.php
--
Un ordinateur résout des problèmes que nous n'aurions pas sans lui
Technique aéronautique : http://aviatechno.net
Avatar
Otomatic
"Pierre www.aribaut.com" écrivait :
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?

Bonjour,
Quelques exemples provenant de FluxBB (Très similaire à PunBB), par
exemple dans le fichier parser.php.
$temp = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $text);

est remplacé par :
$temp = preg_replace_callback($re_list, function($matches) { return preparse_list_tag($matches[2], $matches[1]); }, $text);
$content = preg_replace_callback($re_list, create_function('$matches', 'return handle_list_tag($matches[2], $matches[1]);'), $content);

est remplacé par :
$content = preg_replace_callback($re_list, function($matches) { return handle_list_tag($matches[2], $matches[1]); }, $content);
$text = preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s', create_function('$matches', 'global $lang_common; return "</p><div class="quotebox"><cite>".str_replace(array('[', '"'), array('&#91;', '"'), $matches[2])." ".$lang_common['wrote']."</cite><blockquote><div><p>";'), $text);

est remplacé par :
$text = preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s', function($matches) use ($lang_common) { return '</p><div class="quotebox"><cite>'.str_replace(array('[', '"'), array('&#91;', '"'), $matches[2])." {$lang_common['wrote']}</cite><blockquote><div><p>"; }, $text);

Où ça devient un peu plus compliqué, c'est lorsque la fonction callback
est effectuée sur des éléments de tableau, comme par la ligne
$text = preg_replace_callback($pattern_callback[$i], create_function('$matches', 'return '.$replace_callback[$i].';'), $text);

qui est remplacée par :
$text = preg_replace_callback($pattern_callback[$i], $replace_callback[$i], $text);

donc, ce seront les éléments du tableau $replace_callback[] qui
contiendront la fonction anonyme, par exemple :
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1], $matches[2])';

sera remplacé par :
$replace_callback[] = function($matches) { return handle_url_tag($matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag($matches[1], $matches[2]); };
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1], $matches[2]); };

--
Un ordinateur résout des problèmes que nous n'aurions pas sans lui
Technique aéronautique : http://aviatechno.net
Avatar
www.pierre.aribaut.com
Le 25/03/2018 à 16:44, Otomatic a écrit :
"Pierre www.aribaut.com" écrivait :
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?

La meilleure manière de trouver une réponse ne serait-il pas d'aller
voir la documentation PHP ?
Par exemple :
http://php.net/manual/fr/function.create-function.php
puis ce qui est préconisé en remplacement :
http://php.net/manual/fr/functions.anonymous.php
Migration de PHP 7.1 vers 7.2
http://php.net/manual/fr/migration72.php

Merci, j'avais vu la fonction "anonymous" mais c'est encore un peu du
chinois pour moi ;)
--
http://zetrader.info & http://zetrader.fr
http://aribaut.com - http://zeforums.com
Avatar
www.pierre.aribaut.com
Le 27/03/2018 à 16:06, Otomatic a écrit :
"Pierre www.aribaut.com" écrivait :
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?

Bonjour,
Quelques exemples provenant de FluxBB (Très similaire à PunBB), par
exemple dans le fichier parser.php.
$temp = preg_replace_callback($re_list, create_function('$matches', 'return preparse_list_tag($matches[2], $matches[1]);'), $text);

est remplacé par :
$temp = preg_replace_callback($re_list, function($matches) { return preparse_list_tag($matches[2], $matches[1]); }, $text);

$content = preg_replace_callback($re_list, create_function('$matches', 'return handle_list_tag($matches[2], $matches[1]);'), $content);

est remplacé par :
$content = preg_replace_callback($re_list, function($matches) { return handle_list_tag($matches[2], $matches[1]); }, $content);

$text = preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s', create_function('$matches', 'global $lang_common; return "</p><div class="quotebox"><cite>".str_replace(array('[', '"'), array('&#91;', '"'), $matches[2])." ".$lang_common['wrote']."</cite><blockquote><div><p>";'), $text);

est remplacé par :
$text = preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s', function($matches) use ($lang_common) { return '</p><div class="quotebox"><cite>'.str_replace(array('[', '"'), array('&#91;', '"'), $matches[2])." {$lang_common['wrote']}</cite><blockquote><div><p>"; }, $text);

Où ça devient un peu plus compliqué, c'est lorsque la fonction callback
est effectuée sur des éléments de tableau, comme par la ligne
$text = preg_replace_callback($pattern_callback[$i], create_function('$matches', 'return '.$replace_callback[$i].';'), $text);

qui est remplacée par :
$text = preg_replace_callback($pattern_callback[$i], $replace_callback[$i], $text);

donc, ce seront les éléments du tableau $replace_callback[] qui
contiendront la fonction anonyme, par exemple :
$replace_callback[] = 'handle_url_tag($matches[1])';
$replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1], $matches[2])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1])';
$replace_callback[] = 'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1], $matches[2])';

sera remplacé par :
$replace_callback[] = function($matches) { return handle_url_tag($matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag($matches[1], $matches[2]); };
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1], $matches[2]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1]); };
$replace_callback[] = function($matches) { return handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1], $matches[2]); };


Merci beaucop, je n'aurai pas trouvé tout seul comment faire ce genre de
truc, trop faible niveau de php (je connais juste 2/3 trucs).
--
http://zetrader.info & http://zetrader.fr
http://aribaut.com - http://zeforums.com
Avatar
www.pierre.aribaut.com
Le 30/03/2018 à 12:20, www.pierre.aribaut.com a écrit :
Le 27/03/2018 à 16:06, Otomatic a écrit :
"Pierre www.aribaut.com" écrivait :
Hello, pour un script de forum (PunBB), la fonction create_function()
encore valable sous php 7.1 n'est plus valable en passant à php 7.2.
Par quoi faut-il la remplacer ?

Bonjour,
Quelques exemples provenant de FluxBB (Très similaire à PunBB), par
exemple dans le fichier parser.php.
$temp = preg_replace_callback($re_list, create_function('$matches',
'return preparse_list_tag($matches[2], $matches[1]);'), $text);

est remplacé par :
$temp = preg_replace_callback($re_list, function($matches) { return
preparse_list_tag($matches[2], $matches[1]); }, $text);

$content = preg_replace_callback($re_list,
create_function('$matches', 'return handle_list_tag($matches[2],
$matches[1]);'), $content);

est remplacé par :
$content = preg_replace_callback($re_list, function($matches) {
return handle_list_tag($matches[2], $matches[1]); }, $content);

$text =
preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s',
create_function('$matches', 'global $lang_common; return "</p><div
class="quotebox"><cite>".str_replace(array('[', '"'),
array('&#91;', '"'), $matches[2])."
".$lang_common['wrote']."</cite><blockquote><div><p>";'), $text);

est remplacé par :
$text =
preg_replace_callback('%[quote=(&quot;|&#039;|"|'|)([^rn]*?)1]%s',
function($matches) use ($lang_common) { return '</p><div
class="quotebox"><cite>'.str_replace(array('[', '"'),
array('&#91;', '"'), $matches[2])."
{$lang_common['wrote']}</cite><blockquote><div><p>"; }, $text);

Où ça devient un peu plus compliqué, c'est lorsque la fonction callback
est effectuée sur des éléments de tableau, comme par la ligne
$text = preg_replace_callback($pattern_callback[$i],
create_function('$matches', 'return '.$replace_callback[$i].';'),
$text);

qui est remplacée par :
$text = preg_replace_callback($pattern_callback[$i],
$replace_callback[$i], $text);

donc, ce seront les éléments du tableau $replace_callback[] qui
contiendront la fonction anonyme, par exemple :
    $replace_callback[] = 'handle_url_tag($matches[1])';
    $replace_callback[] = 'handle_url_tag($matches[1], $matches[2])';
    $replace[] = '<a href="mailto:$1">$1</a>';
    $replace[] = '<a href="mailto:$1">$2</a>';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewtopic.php?id='.$matches[1],
$matches[2])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1],
$matches[2])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/viewforum.php?id='.$matches[1],
$matches[2])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1])';
    $replace_callback[] =
'handle_url_tag(''.get_base_url(true).'/profile.php?id='.$matches[1],
$matches[2])';

sera remplacé par :
    $replace_callback[] = function($matches) { return
handle_url_tag($matches[1]); };
    $replace_callback[] = function($matches) { return
handle_url_tag($matches[1], $matches[2]); };
    $replace[] = '<a href="mailto:$1">$1</a>';
    $replace[] = '<a href="mailto:$1">$2</a>';
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewtopic.php?id='.$matches[1],
$matches[2]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1]);
};
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewtopic.php?pid='.$matches[1].'#p'.$matches[1],
$matches[2]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/viewforum.php?id='.$matches[1],
$matches[2]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1]); };
    $replace_callback[] = function($matches) { return
handle_url_tag(get_base_url(true).'/profile.php?id='.$matches[1],
$matches[2]); };


Merci beaucop, je n'aurai pas trouvé tout seul comment faire ce genre de
truc, trop faible niveau de php (je connais juste 2/3 trucs).

Pardon, merci *beaucoup* pour cette réponse détaillée.
--
http://zetrader.info & http://zetrader.fr
http://aribaut.com - http://zeforums.com