My webhotel have uppgrade to PHP version 8.0 The code is working but it's showing warningmessage on the homepage now.
I'ts something with my array.
Warning: Undefined array key "JS" in /customers/c/c/4/plf1x2.dk/httpd.www/test/svspeuro.php on line 1465
Warning: Undefined array key "Vinst" in /customers/c/c/4/plf1x2.dk/httpd.www/test/svspeuro.php on line 1465
Warning: Undefined array key "PWB" in /customers/c/c/4/plf1x2.dk/httpd.www/test/svspeuro.php on line 1468 Warning:
Undefined array key "Vinst" in /customers/c/c/4/plf1x2.dk/httpd.www/test/svspeuro.php on line 1468 Warning:
Undefined array key "oavgjord" in /customers/c/c/4/plf1x2.dk/httpd.www/test/svspeuro.php on line 1471 here
I Have tried with
enterif (isset($matchesLines[$Borta_Lag]['omgångar'])){
$matchesLines[$Borta_Lag]['omgångar']+=1;
} code here
but it doesnt work it's get a empty value.
Here is the code.
I hope someone can help me?
// Sorterar ut lagnamn och resultat
$file = file($filename);
$result = array_merge($file,$resultatarray)
$matchesLines = array();
foreach($result as $line) {
if(preg_match('/^([a-öA-Ö]+\D)-([a-öA-Ö]+\D) (\d+)-(\d+)/', $line, $data)){
$Hemma_Lag = $data[1];
$Borta_Lag = $data[2];
$Hemma_Resultat = $data[3];
$Borta_Resultat=$data[4];
$matchesLines[$Hemma_Lag]['Vinst'] += 0;
$matchesLines[$Borta_Lag]['Vinst'] += 0;
$matchesLines[$Hemma_Lag]['oavgjord'] += 0;
$matchesLines[$Borta_Lag]['oavgjord'] += 0;
$matchesLines[$Hemma_Lag]['Förlust'] += 0;
$matchesLines[$Borta_Lag]['Förlust'] += 0;
if ($Hemma_Resultat == $Borta_Resultat){
$matchesLines[$Hemma_Lag]['lag'] = $Hemma_Lag;
$matchesLines[$Hemma_Lag]['poang']+=1;
$matchesLines[$Hemma_Lag]['mål'] += $Hemma_Resultat;
$matchesLines[$Hemma_Lag]['måli'] += $Borta_Resultat;
$matchesLines[$Hemma_Lag]['oavgjord'] += 1;
$matchesLines[$Borta_Lag]['lag'] = $Borta_Lag;
$matchesLines[$Borta_Lag]['poang'] +=1;
$matchesLines[$Borta_Lag]['mål'] += $Borta_Resultat;
$matchesLines[$Borta_Lag]['måli'] += $Hemma_Resultat;
$matchesLines[$Borta_Lag]['oavgjord'] += 1;
}
if ($Hemma_Resultat > $Borta_Resultat){
$matchesLines[$Hemma_Lag]['lag'] = $Hemma_Lag;
$matchesLines[$Hemma_Lag]['poang']+=3;
$matchesLines[$Hemma_Lag]['mål'] += $Hemma_Resultat;
$matchesLines[$Hemma_Lag]['måli'] += $Borta_Resultat;
$matchesLines[$Hemma_Lag]['Vinst'] += 1;
$matchesLines[$Borta_Lag]['lag'] = $Borta_Lag;
$matchesLines[$Borta_Lag]['poang'] +=0;
$matchesLines[$Borta_Lag]['mål'] += $Borta_Resultat;
$matchesLines[$Borta_Lag]['måli'] += $Hemma_Resultat;
$matchesLines[$Borta_Lag]['Förlust'] += 1;
}
if ($Hemma_Resultat < $Borta_Resultat) {
$matchesLines[$Hemma_Lag]['lag'] = $Hemma_Lag;
$matchesLines[$Hemma_Lag]['poang']+=0;
$matchesLines[$Hemma_Lag]['Förlust'] += 1;
$matchesLines[$Hemma_Lag]['mål'] += $Hemma_Resultat;
$matchesLines[$Hemma_Lag]['måli'] += $Borta_Resultat;
$matchesLines[$Borta_Lag]['lag'] = $Borta_Lag;
$matchesLines[$Borta_Lag]['poang'] +=3;
$matchesLines[$Borta_Lag]['Vinst'] += 1;
$matchesLines[$Borta_Lag]['mål'] += $Borta_Resultat;
$matchesLines[$Borta_Lag]['måli'] += $Hemma_Resultat;
}
if (isset($matchesLines[$Borta_Lag])){
$matchesLines[$Borta_Lag]['omgångar']+=1;
$matchesLines[$Hemma_Lag]['omgångar']+=1;
}
}
}
Yes, PHP 8.0 has elevated this notice and a bunch of other notices to now be warnings :
A number of notices have been converted into warnings:
Attempting to read an undefined variable.
Attempting to read an undefined property.
Attempting to read an undefined array key.
...
Related
There was a problem with the old slowAES library.
When trying to decrypt, in js it produces one, and in php it produces another.
There are a lot of errors in the console that I can’t figure out.
Tell me what's wrong? How to get the same keys?
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$a = "cd36b76f96b103402924bd5f76d3c204";
$b = "680eb6a492f48ea1b342aea7b79e18eb";
$c = "f746749b113236227058bd471f5c91dc";
function toHex($args){
if(func_num_args() != 1 || !is_array($args)){
$args = func_get_args();
}
$ret = '';
for($i = 0; $i < count($args) ;$i++)
$ret .= sprintf('%02x', $args[$i]);
return $ret;
}
function toNumbers($s){
$ret = array();
for($i=0; $i<strlen($s); $i+=2){
$ret[] = hexdec(substr($s, $i, 2));
}
return $ret;
}
function getRandom($min,$max){
if($min === null)
$min = 0;
if($max === null)
$max = 1;
return mt_rand($min, $max);
}
function generateSharedKey($len){
if($len === null)
$len = 16;
$key = array();
for($i = 0; $i < $len; $i++)
$key[] = getRandom(0,255);
return $key;
}
function generatePrivateKey($s,$size){
if(function_exists('mhash') && defined('MHASH_SHA256')){
return convertStringToByteArray(substr(mhash(MHASH_SHA256, $s), 0, $size));
}else{
throw new Exception('cryptoHelpers::generatePrivateKey currently requires mhash');
}
}
function convertStringToByteArray($s){
$byteArray = array();
for($i = 0; $i < strlen($s); $i++){
$byteArray[] = ord($s[$i]);
}
return $byteArray;
}
function convertByteArrayToString($byteArray){
$s = '';
for($i = 0; $i < count($byteArray); $i++){
$s .= chr($byteArray[$i]);
}
return $s;
}
include 'cryptovh/aes.php';
$aes = new AES();
$token = $aes->decrypt(toNumbers($c), 16, 2, toNumbers($a), 16, toNumbers($b));
echo toHex($token); // WHAT I HAVE
echo "<br>";
echo "016e9be78dd5130beb5febcd328ff588"; // WHAT I NEED
?>
cryptovh/aes.php
that is copy of: https://github.com/aleaxit/slowaes/blob/master/php/aes_fast.php
use this library:
https://github.com/aleaxit/slowaes
At the output, I get this token:
dd2f6d60b939b390dc19688babc3873d
And console errors:
Notice: Undefined offset: 16 in
/var/www/myuser/data/www/example.com/cryptovh/aes.php on line 386
Notice: Undefined index: in
/var/www/myuser/data/www/example.com/cryptovh/aes.php on line 386
Notice: Undefined offset: 20 in
/var/www/myuser/data/www/example.com/cryptovh/aes.php on line 386
Notice: Undefined index: in
/var/www/myuser/data/www/example.com/cryptovh/aes.php on line 386
Notice: Undefined offset: 24 in
/var/www/myuser/data/www/example.com/cryptovh/aes.php on line 386
Notice: Undefined index: in
/var/www/myuser/data/www/example.com/panel/cryptovh/aes.php on line
386
In slowaes/php/aes_fast.php, the inversion of the MixColumns operation in the mixColumns method is implemented incorrectly, the else-block must be:
...
} else {
for ($c = 0; $c < 4; $c++) {
$t[ $c] = self::$GEX[$state[$c]] ^ self::$GBX[$state[4+$c]] ^ self::$GDX[$state[8+$c]] ^ self::$G9X[$state[12+$c]];
$t[ 4+$c] = self::$G9X[$state[$c]] ^ self::$GEX[$state[4+$c]] ^ self::$GBX[$state[8+$c]] ^ self::$GDX[$state[12+$c]];
$t[ 8+$c] = self::$GDX[$state[$c]] ^ self::$G9X[$state[4+$c]] ^ self::$GEX[$state[8+$c]] ^ self::$GBX[$state[12+$c]];
$t[12+$c] = self::$GBX[$state[$c]] ^ self::$GDX[$state[4+$c]] ^ self::$G9X[$state[8+$c]] ^ self::$GEX[$state[12+$c]];
}
}
...
The inverse of the MixColumns operation is required for decryption.
There is also a typo in the method invMain, line 3, where i must be replaced by $i.
With these changes, the expected result is obtained, which can be verified e.g. here. The warnings are also no longer displayed.
I've filed an issue here. Note the ReadMe: The code is intended more for didactic purposes. In practice, openssl_encrypt / openssl_decrypt or similar should be used.
I receive the following PHP notice
PHP Notice: Undefined offset: 0
Here is a sample of what causes the error.
$file = $_SERVER['DOCUMENT_ROOT']."/savedposts/edited".$post_id.".txt";
$saved_content = file_get_contents($_SERVER['DOCUMENT_ROOT']."/savedposts/".$post_id.".txt");
$cct = 0;
$contexttext = array();
for ($i = 0; $i < strlen($saved_content); $i++) {
if (substr($saved_content, $i, 9) == "[Context]") {
$i = $i + 9;
while (substr($saved_content, $i, 10) !== "[/Context]") {
$contexttext[$cct] .= substr($saved_content, $i, 1);
$i++;
}
$cct++;
}
}
The error is on this line
$contexttext[$cct] .= substr($saved_content, $i, 1);
How to fix the notice.
To replicate this:
$cct = 0;
$contexttext = array();
$contexttext[$cct] .= 'test';
Here 'test' is being appended to $contexttext[$cct], which evaluates to: $contexttext[0]. However there is nothing at [0] yet, because it's an empty array, we can't append to something that doesn't exist
If however you'd done this:
$cct = 0;
$contexttext = array();
$contexttext[$cct] = '';
$contexttext[$cct] .= 'test';
Then the notice would dissapear, because now when we append a string, we have something to append it to
I have a code in use and it generates a PHP error in the second "for" loop.
PHP Notice: Undefined variable: newmatches
if (empty($result['ERR'])) {
preg_match_all('(<h3><a[^<>]*href="([^<>]*)"[^<>]*>(.*)</a>\s*</h3>)siU', $result['EXE'], $matches);
for ($i = 0; $i < count($matches[1]); $i++) {
$matches[1][$i] = urldecode($matches[1][$i]);
preg_match_all('/\*\*(http:\/\/.*$)/siU', $matches[1][$i], $urls);
$newmatches[1][$i] = $urls[1][0];
}
for ($i = 0; $i < count($newmatches[1]); $i++) { //PHP Notice: Undefined variable: newmatches
if(strstr($newmatches[1][$i], $domain))
return $i+1;
}
} else {
return '0';
}
Thank you in advance!
I don't see anywhere where $newmatches would be set, aside from the first for loop, which won't run if count($matches[1]) is 0.
Not sure what all this hardcoding of your index to 1 is about, but a simple fix is to set $newmatches[1] = array() before the first loop.
This question already has answers here:
What causes: "Notice: Uninitialized string offset" to appear? [closed]
(5 answers)
Closed 9 years ago.
I have a text file write.txt:-write.txt
My name
jai hind
stack
I am getting the error in the following code at line 154 and 165 and the error is:-
PHP Notice: Uninitialized string offset: 11 in /home/sakshi/Desktop/syllabify/step2/Syll_script_1.php on line 154
PHP Notice: Undefined offset: -2 in /home/sakshi/Desktop/syllabify/step2/Syll_script_1.php on line 165
code:-
$file1 = fopen("write.txt", "r");
$q=1;
while ( $line = fgets($file1) )
{
$i=0;
$arr = explode( "\n", $line );
$q=$q+1;
if(strcmp($arr[0],"." ) == 0)
{
$i=1;
$q=$q-1;
echo "\nposition of dot in write.txt:";
echo "$i \t $q\n";
break;
}
}
fclose($file1);
if($i==0)
echo $i;
while ( $q!=1 )
{
$file_input=fopen("input.txt","r");
$line = fgets($file_input);
$p = strlen($line);
echo $p;
$a=2;
if ($p == $a)
{
$m = $line[0];
echo "$m\n";
$l=0; $h=0;
$filename=fopen("write.txt","r");
$content=file("write.txt");
for($i=0;$i<$u-1;$i++)
{
$arr=$content[$i];
$length=strlen($arr);
for($j=0;$j<=$length;$j++)
{
if(strcmp($arr[$j],$m ) == 0)// line 154
{
echo "\nYES PRESENT AT LINE NUMBER: ";
$h=$i+1;
echo "$h\n";
$l=$h+1;
}
}
break;
}
/********************************************************/
$arr3=$content[$l-2];// line 165
$ar3=explode(" ",$arr3);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[0]);
fwrite($output_file," ");
fclose($output_file);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[1]);
fwrite($output_file," ");
fclose($output_file);
$ar3=str_replace("\n","",$ar3);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[2]);
fclose($output_file);
/************************************************************/
// put enter at the end of operation
$output_file=fopen("Result.txt","a");
fwrite($output_file,"\n");
fclose($output_file);
/**********************************************************/
}
The problem is in the following line:
for($j = 0; $j <= $length; $j++)
it should be
for($j = 0; $j < $length; $j++)
Without the '=' sign. Because with the equal sign the iteration will exceed the length of the string. Counting start at 0 until strlen()-1. Thus
$j < strlen();
Otherwise you should apply
$j <= strlen() - 1;
Check if $arr is an array before access to an element.
I'm working to parse the following string but at the same time trying to get rid of the current undefined offset on the index array. I would appreciate some help w/ the undefined offset issue.
error_reporting(E_ALL);
ini_set('display_errors', '1');
function my_recursion($String, &$Inc) {
$l = strlen($String);
$has_quotes = 0; $array = array();
$x= 0;
for ($Inc; $Inc < $l; $Inc++) {
$my_char = $String[$Inc];
if ($my_char == '(' && !$has_quotes) {
$Inc++;
$array[$x] = my_recursion($String, $Inc);
$x++;
} else if ($my_char == '"') {
$has_quotes = !$has_quotes;
if (!$has_quotes)
$x++;
} else if ($has_quotes) {
$array[$x] .= $my_char;
}
}
print_r($array);
}
$String = '(("HELLO"("BAR")("FOO")()""))';
$Inc = 0;
(my_recursion($String, $Inc));
To get rid of the errors, add this line to the start of your function:
$array = array();
and replace this line:
$array[$x] .= $my_char;
with this:
$array[$x] = isset($array[$x])? $array[$x].$my_char : $my_char;
For help with your recursion, you'll need to describe its desired behavior.