fonksiyonu patlayabilir php yerine dizi undefinded değişkeni dönen tutar

2 Cevap php

rgborhex işlevi tanımlanmamış bir değişken Returing edilir:

function rgborhex($unformatedColor){
if(strpos($unformatedColor, "-") == false) { //did not find a - in the color string; is not in rgb form; convert
    $rgbColor = hextorgb($unformatedColor);
    $rgbColor = explode("-", $rgbColor);
    return $rgbColor;
}
else { // found a - in the color string; is in rgb form; return
    $rgbColor = $unformatedColor;
    $rgbColor = explode("-", $rgbColor);
    return $rbgColor;
}
}

function hextorgb($hex) {
if(strlen($hex) == 3) {
    $hrcolor = hexdec(substr($hex, 0, 1));      //r
    $hrcolor .= "-" . hexdec(substr($hex, 1, 1));   //g
    $hrcolor .= "-" . hexdec(substr($hex, 2, 1));   //b
}
else if(strlen($hex) == 6) {
    $hrcolor = hexdec(substr($hex, 0, 2));      //r
    $hrcolor .= "-" . hexdec(substr($hex, 2, 2)); //g
    $hrcolor .= "-" . hexdec(substr($hex, 4, 2)); //b
}
return $hrcolor;

}

2 Cevap

-return $rbgColor;
+return $rgbColor;

Sadece bir ikinci return tablosunda yazım hatası :)


Alternatif - Küçük düzenlemeler, IMO daha kolay okunur:

function rgborhex($unformatedColor) {
    if (strpos($unformatedColor, '-') === false) { //did not find a - in the color string; is not in rgb form; convert
        $unformatedColor = hextorgb($unformatedColor);
    }

    return explode('-', $unformatedColor);
}

E_STRICT | E_ALL üzerine error_reporting koyunuz. Bu bir beklediğinizden çok daha fazla hataları dönmek PHP yapar.