Recently updated to PHP 7.1 and start getting following error
Warning: A non-numeric value encountered in on line 29
Here is wha
In my case it was because of me used +
as in other language but in PHP strings concatenation operator is .
.
in PHP if you use + for concatenation you will end up with this error. In php + is a arithmetic operator. https://www.php.net/manual/en/language.operators.arithmetic.php
wrong use of + operator:
"<label for='content'>Content:</label>"+
"<textarea class='form-control col-xs-12' rows='7'cols='100' id='content' name='content'>"+$initcontent+"</textarea>'"+
"</div>";
use . for concatenation
$output = "<div class='from-group'>".
"<label for='content'>Content:</label>".
"<textarea class='form-control col-xs-12' rows='7'cols='100' id='content' name='content'>".$initcontent."</textarea>'".
"</div>";
It seems that in PHP 7.1, a Warning will be emitted if a non-numeric value is encountered. See this link.
Here is the relevant portion that pertains to the Warning notice you are getting:
New E_WARNING and E_NOTICE errors have been introduced when invalid strings are coerced using operators expecting numbers or their assignment equivalents. An E_NOTICE is emitted when the string begins with a numeric value but contains trailing non-numeric characters, and an E_WARNING is emitted when the string does not contain a numeric value.
I'm guessing either $item['quantity'] or $product['price'] does not contain a numeric value, so make sure that they do before trying to multiply them. Maybe use some sort of conditional before calculating the $sub_total, like so:
<?php
if (is_numeric($item['quantity']) && is_numeric($product['price'])) {
$sub_total += ($item['quantity'] * $product['price']);
} else {
// do some error handling...
}
I had this issue with my pagination forward and backward link .... simply set (int ) in front of the variable $Page+1 and it worked...
<?php
$Page = (isset($_GET['Page']) ? $_GET['Page'] : '');
if ((int)$Page+1<=$PostPagination) {
?>
<li> <a href="Index.php?Page=<?php echo $Page+1; ?>"> »</a></li>
<?php }
?>
Check if you're not incrementing with some variable that its value is an empty string like ''.
Example:
$total = '';
$integers = range(1, 5);
foreach($integers as $integer) {
$total += $integer;
}
Hello, In my case using (WordPress) and PHP7.4 I get a warning about numeric value issue. So I changed the old code as follow:
From:
$val = $oldval + $val;
To:
$val = ((int)$oldval + (int)$val);
Now the warning disappeared :)