Fonction each() obsolete depuis PHP7.2.0
chabinot
Messages postés
391
Statut
Membre
-
chabinot Messages postés 391 Statut Membre -
chabinot Messages postés 391 Statut Membre -
Bonjour,
La version de PHP que j'utilise est la 7.2.0, j'utilise l'IDE Sublime Text 3 et ce dernier utilise la fonction each() qui est dépréciée depuis la version 7.2.0 de PHP. Ce qui fait qu'à chaque fois que je crée un fichier .php, il me crée un fichier .php.tmp avec le message suivant:
"Deprecated: The each() function is deprecated. This message will be suppressed on further calls in C:\Users\amaury\AppData\Roaming\Sublime Text 3\Packages\PHPTools\php.tools\codeFormatter.php on line 54"
Voici le code de la ligne 54 du fichier de Sublime Text :
qui se trouve dans le bloc suivant :
Je ne sais pas par quoi remplacer cette fonction. C'est un peu génant, car il me décale toutes mes indentations.
Merci de votre aide à tous.
Cordialement
La version de PHP que j'utilise est la 7.2.0, j'utilise l'IDE Sublime Text 3 et ce dernier utilise la fonction each() qui est dépréciée depuis la version 7.2.0 de PHP. Ce qui fait qu'à chaque fois que je crée un fichier .php, il me crée un fichier .php.tmp avec le message suivant:
"Deprecated: The each() function is deprecated. This message will be suppressed on further calls in C:\Users\amaury\AppData\Roaming\Sublime Text 3\Packages\PHPTools\php.tools\codeFormatter.php on line 54"
Voici le code de la ligne 54 du fichier de Sublime Text :
while (list($index, $token) = each($this->tkns)) {
qui se trouve dans le bloc suivant :
final class AddMissingCurlyBraces extends FormatterPass {
public function format($source) {
$tmp = $this->addBraces($source);
while (true) {
$source = $this->addBraces($tmp);
if ($source == $tmp) {
break;
}
$tmp = $source;
}
return $source;
}
private function addBraces($source) {
$this->tkns = token_get_all($source);
$this->code = '';
while (list($index, $token) = <gras>each($this->tkns)</gras>) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
switch ($id) {
case T_FOR:
$this->append_code($text, false);
$paren_count = null;
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
if (ST_PARENTHESES_OPEN == $id) {
$paren_count++;
} elseif (ST_PARENTHESES_CLOSE == $id) {
$paren_count--;
}
$this->append_code($text, false);
if (0 === $paren_count && !$this->is_token(array(T_COMMENT, T_DOC_COMMENT))) {
break;
}
}
if (!$this->is_token(ST_CURLY_OPEN) && !$this->is_token(ST_COLON)) {
$ignore_count = 0;
if (!$this->is_token(array(T_COMMENT, T_DOC_COMMENT), true)) {
$this->append_code($this->new_line . '{');
} else {
$this->append_code('{');
}
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
if (ST_PARENTHESES_OPEN == $id || ST_CURLY_OPEN == $id || ST_BRACKET_OPEN == $id) {
$ignore_count++;
} elseif (ST_PARENTHESES_CLOSE == $id || ST_CURLY_CLOSE == $id || ST_BRACKET_CLOSE == $id) {
$ignore_count--;
}
$this->append_code($text, false);
if ($ignore_count <= 0 && !($this->is_token(ST_CURLY_CLOSE) || $this->is_token(ST_SEMI_COLON) || $this->is_token(array(T_WHILE))) && (ST_CURLY_CLOSE == $id || ST_SEMI_COLON == $id || T_ELSE == $id || T_ELSEIF == $id)) {
break;
}
}
$this->append_code($this->get_crlf_indent() . '}' . $this->get_crlf_indent(), false);
break 2;
}
break;
case T_IF:
case T_ELSEIF:
$this->append_code($text, false);
$paren_count = null;
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
if (ST_PARENTHESES_OPEN == $id) {
$paren_count++;
} elseif (ST_PARENTHESES_CLOSE == $id) {
$paren_count--;
}
$this->append_code($text, false);
if (0 === $paren_count && !$this->is_token(array(T_COMMENT, T_DOC_COMMENT))) {
break;
}
}
if (!$this->is_token(ST_CURLY_OPEN) && !$this->is_token(ST_COLON)) {
$ignore_count = 0;
if (!$this->is_token(array(T_COMMENT, T_DOC_COMMENT), true)) {
// $this->append_code($this->new_line.'{'.$this->new_line);
$this->append_code($this->new_line . '{');
} else {
// $this->append_code('{'.$this->new_line);
$this->append_code('{');
}
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
if (ST_PARENTHESES_OPEN == $id || ST_CURLY_OPEN == $id || ST_BRACKET_OPEN == $id) {
$ignore_count++;
} elseif (ST_PARENTHESES_CLOSE == $id || ST_CURLY_CLOSE == $id || ST_BRACKET_CLOSE == $id) {
$ignore_count--;
}
$this->append_code($text, false);
if ($ignore_count <= 0 && !($this->is_token(ST_CURLY_CLOSE) || $this->is_token(ST_SEMI_COLON) || $this->is_token(array(T_WHILE))) && (ST_CURLY_CLOSE == $id || ST_SEMI_COLON == $id || T_ELSE == $id || T_ELSEIF == $id)) {
break;
}
}
$this->append_code($this->get_crlf_indent() . '}' . $this->get_crlf_indent(), false);
break 2;
}
break;
case T_ELSE:
$this->append_code($text, false);
if (!$this->is_token(ST_CURLY_OPEN) && !$this->is_token(ST_COLON) && !$this->is_token(array(T_IF))) {
$ignore_count = 0;
$this->append_code('{' . $this->new_line);
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
if (ST_PARENTHESES_OPEN == $id || ST_CURLY_OPEN == $id || ST_BRACKET_OPEN == $id) {
$ignore_count++;
} elseif (ST_PARENTHESES_CLOSE == $id || ST_CURLY_CLOSE == $id || ST_BRACKET_CLOSE == $id) {
$ignore_count--;
}
$this->append_code($text, false);
if ($ignore_count <= 0 && !($this->is_token(ST_CURLY_CLOSE) || $this->is_token(ST_SEMI_COLON) || $this->is_token(array(T_WHILE))) && (ST_CURLY_CLOSE == $id || ST_SEMI_COLON == $id || T_ELSE == $id || T_ELSEIF == $id)) {
break;
}
}
$this->append_code($this->get_crlf_indent() . '}' . $this->get_crlf_indent(), false);
break 2;
}
break;
default:
$this->append_code($text, false);
break;
}
}
while (list($index, $token) = each($this->tkns)) {
list($id, $text) = $this->get_token($token);
$this->ptr = $index;
$this->append_code($text, false);
}
return $this->code;
}
}
Je ne sais pas par quoi remplacer cette fonction. C'est un peu génant, car il me décale toutes mes indentations.
Merci de votre aide à tous.
Cordialement
A voir également:
- Deprecated: the each() function is deprecated. this message will be suppressed on further calls
- What is my movie français - Télécharger - Divers TV & Vidéo
- Recuperer message whatsapp supprimé - Guide
- Message absence thunderbird - Guide
- Message supprimé whatsapp - Guide
- Who is on my wifi - Télécharger - Outils Internet
3 réponses
Bonjour,
A mon avis... se remplace sans mal par :
while (list($index, $token) = each($this->tkns)) {
A mon avis... se remplace sans mal par :
foreach($this->tkns as $index=>$token){
yg_be
Messages postés
24281
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 585
bonjour, peut-être simplement:
foreach ($this->tkns as $index => $token){
Merci,
Cela marche, mais j'ai toujours un dérèglement de mes indentations quand je sauvegarde.
Exemple :
devient après sauvegarde :
Et j'ai toujours le fichier .php.tmp qui se génère, sans commentaire.
Je peux mettre tout le source de codeFormatter.php de Sublime avant modification.
Cordialement
Cela marche, mais j'ai toujours un dérèglement de mes indentations quand je sauvegarde.
Exemple :
<article id="post-<?php the_ID();?>" <?php post_class('sunset-format-gallery'); ?>>
devient après sauvegarde :
<article id="post-<?php the_ID();?>" <?php post_class('sunset-format-gallery');?>>
Et j'ai toujours le fichier .php.tmp qui se génère, sans commentaire.
Je peux mettre tout le source de codeFormatter.php de Sublime avant modification.
Cordialement