I am trying to include
two .php
files into another .php
file that's included in index.php
.
Their contents is irrelevant to the issue because with just one include
it works fine.
I have the following files:
index.php
<!DOCTYPE html>
<html>
<?php
include('inputs.php');
?>
.
.
.
</html>
inputs.php
<?php
include('hex_to_rgb.php');
// include('rgb_to_hex.php');
.
.
.
?>
hex_to_rgb.php
<?php
class RGB
{
public $R;
public $G;
public $B;
}
function HexadecimalToDecimal($hex)
{
$hex = strtoupper($hex);
$hexLength = strlen($hex);
$dec = 0;
for ($i = 0; $i < $hexLength; $i++)
{
$b = $hex[$i];
if ($b >= 48 && $b <= 57)
$b -= 48;
else if ($b >= 65 && $b <= 70)
$b -= 55;
$dec += $b * pow(16, (($hexLength - $i) - 1));
}
return (int)$dec;
}
function HexadecimalToRGB($hex) {
if ($hex[0] == '#')
$hex = substr($hex, 1);
$rgb = new RGB();
$rgb->R = floor(HexadecimalToDecimal(substr($hex, 0, 2)));
$rgb->G = floor(HexadecimalToDecimal(substr($hex, 2, 2)));
$rgb->B = floor(HexadecimalToDecimal(substr($hex, 4, 2)));
return $rgb;
}
?>
rgb_to_hex.php
<?php
class RGB
{
public $R;
public $G;
public $B;
}
function DecimalToHexadecimal($dec)
{
if ($dec < 1) return "00";
$hex = $dec;
$hexStr = "";
while ($dec > 0)
{
$hex = $dec % 16;
if ($hex < 10)
$hexStr = substr_replace($hexStr, chr($hex + 48), 0, 0);
else
$hexStr = substr_replace($hexStr, chr($hex + 55), 0, 0);
$dec = floor($dec / 16);
}
return $hexStr;
}
function RGBToHexadecimal($rgb) {
$rs = DecimalToHexadecimal($rgb->R);
$gs = DecimalToHexadecimal($rgb->G);
$bs = DecimalToHexadecimal($rgb->B);
return "#" . $rs . $gs . $bs;
}
?>
The only problem that I see is that both hex_to_rgb.php
and rgb_to_hex.php
declare and use similar variables, methods and classes.
But the thing is that I don't use any of those variables, methods or classes inside inputs.php
.
I've added the following code inside index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '0');
?>
<?php
print_r(array_keys(get_defined_vars()));
print_r(array_values(get_defined_vars()));
?>
I don't see any error when it's just one include. But when I have two includes, I don't see anything, because everything is white. It's almost hypnotic.
What do you think ?
EDIT:
I've ended up deleting both hex_to_rgb.php
and rgb_to_hex.php
and modifying and using just one function that suits my needs:
function HexadecimalToRGB($hex) {
if ($hex[0] == '#')
$hex = substr($hex, 1);
$rgb = floor(hexdec(substr($hex, 0, 2)))." ".
floor(hexdec(substr($hex, 2, 2)))." ".
floor(hexdec(substr($hex, 4, 2)));
return $rgb;
}