Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Jan 15, 2025
1 parent f62116a commit a9246c8
Showing 1 changed file with 69 additions and 23 deletions.
92 changes: 69 additions & 23 deletions index/p-h-p.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function p_h_p(?string $from): ?string {
$in_array = $is_array = 0;
$to = "";
foreach ($lot as $k => $v) {
$open = '<?php ' === \substr($to, -6);
if ('stdclass' === \strtolower(\substr($to, -8)) && \preg_match('/\bnew \\\\?stdclass$/i', $to, $m)) {
$to = \trim(\substr($to, 0, -\strlen($m[0]))) . '(object)[]';
}
Expand All @@ -35,9 +36,11 @@ function p_h_p(?string $from): ?string {
}
if ('_CAST' === \substr(\token_name($v[0]), -5)) {
$cast = \trim(\substr($v[1], 1, -1));
if ('boolean' === $cast) {
$cast = 'bool';
} else if ('double' === $cast || 'real' === $cast) {
if ('bool' === $cast || 'boolean' === $cast) {
$to .= '!!';
continue;
}
if ('double' === $cast || 'real' === $cast) {
$cast = 'float';
} else if ('integer' === $cast) {
$cast = 'int';
Expand Down Expand Up @@ -68,7 +71,21 @@ function p_h_p(?string $from): ?string {
if ('(binary)' === \substr($to, -8)) {
$to = \substr($to, 0, -8) . 'b';
}
$to = \trim($to) . $v[1];
if ('(float)' === \substr($to, -7) && "" !== ($test = \filter_var($v[1], \FILTER_SANITIZE_NUMBER_FLOAT, \FILTER_FLAG_ALLOW_FRACTION | \FILTER_FLAG_ALLOW_SCIENTIFIC))) {
$to = \substr($to, 0, -7) . '0+' . $test;
continue;
}
if ('(int)' === \substr($to, -5) && "" !== ($test = \filter_var($v[1], \FILTER_SANITIZE_NUMBER_INT))) {
$to = \substr($to, 0, -5) . '0+' . $test;
continue;
}
if ('(string)' === \substr($to, -8)) {
$to = \substr($to, 0, -8);
}
if (!$open) {
$to = \trim($to);
}
$to .= $v[1];
continue;
}
if (\T_DNUMBER === $v[0]) {
Expand All @@ -90,7 +107,7 @@ function p_h_p(?string $from): ?string {
continue;
}
if (\T_ECHO === $v[0] || \T_PRINT === $v[0]) {
if ('<?php ' === \substr($to, -6)) {
if ($open) {
// Replace `<?php echo` with `<?=`
$to = \substr($to, 0, -4) . '=';
continue;
Expand Down Expand Up @@ -150,34 +167,43 @@ function p_h_p(?string $from): ?string {
if (\T_STRING === $v[0]) {
$test = \strtolower($v[1]);
if ('false' === $test) {
$to = \trim($to) . '!1';
if ('!!' === \substr($to, -2)) {
$to = \substr($to, 0, -2);
}
if (!$open) {
$to = \trim($to);
}
$to .= '!1';
} else if ('null' === $test) {
$to .= $test;
} else if ('true' === $test) {
$to = \trim($to) . '!0';
if ('!!' === \substr($to, -2)) {
$to = \substr($to, 0, -2);
}
if (!$open) {
$to = \trim($to);
}
$to .= '!0';
} else {
$to .= $v[1];
}
continue;
}
// <https://stackoverflow.com/a/16606419/1163000>
if (\T_VARIABLE === $v[0]) {
if ('(bool)' === \substr($to, -6)) {
$to = \substr($to, 0, -6) . '!!' . $v[1];
} else if ('(float)' === \substr($to, -7)) {
$to = \substr($to, 0, -7) . $v[1] . '+0';
if ('(float)' === \substr($to, -7)) {
$to = \substr($to, 0, -7) . '0+' . $v[1];
} else if ('(int)' === \substr($to, -5)) {
$to = \substr($to, 0, -5) . $v[1] . '+0';
$to = \substr($to, 0, -5) . '0+' . $v[1];
} else if ('(string)' === \substr($to, -8)) {
$to = \substr($to, 0, -8) . $v[1] . '.""';
$to = \substr($to, 0, -8) . '"".' . $v[1];
} else if ("\x1a" === \substr($to, -1)) {
$to = \substr($to, 0, -1) . $v[1];
} else {
if ('<?php ' === \substr($to, -6)) {
$to .= $v[1];
} else {
$to = \trim($to) . $v[1];
if (!$open) {
$to = \trim($to);
}
$to .= $v[1];
}
continue;
}
Expand All @@ -187,27 +213,40 @@ function p_h_p(?string $from): ?string {
}
// Math operator(s)
if (false !== \strpos('!%&*+-./<=>?|~', $v[1][0])) {
$to = \trim($to) . $v[1];
if (!$open) {
$to = \trim($to);
}
$to .= $v[1];
continue;
}
$to .= $v[1];
continue;
}
if ($is_array && '(' === $v) {
$in_array += 1;
$to = \trim($to) . '[';
if (!$open) {
$to = \trim($to);
}
$to .= '[';
continue;
}
if ($is_array && ')' === $v) {
if ($in_array === $is_array) {
$in_array -= 1;
$is_array -= 1;
$to = \trim(\trim($to, ',')) . ']';
$to = \trim($to, ',');
if (!$open) {
$to = \trim($to);
}
$to .= ']';
continue;
}
}
if (false !== \strpos('([', $v)) {
$to = \trim($to) . $v;
if (!$open) {
$to = \trim($to);
}
$to .= $v;
continue;
}
if (false !== \strpos(')]', $v)) {
Expand All @@ -216,10 +255,17 @@ function p_h_p(?string $from): ?string {
$to = \substr($to, 0, -1);
continue;
}
$to = \trim(\trim($to, ',')) . $v;
$to = \trim($to, ',');
if (!$open) {
$to = \trim($to);
}
$to .= $v;
continue;
}
$to = \trim($to) . $v;
if (!$open) {
$to = \trim($to);
}
$to .= $v;
}
return "" !== ($to = \trim(\strtr($to, ["\x1a" => ""]))) ? $to : null;
}
Expand Down

0 comments on commit a9246c8

Please sign in to comment.