<?php
define( 'ANIMAL', 'turtles!' );
$constant = constant(...);
echo "I like {$constant('ANIMAL')}";
echo PHP_EOL;
echo PHP_EOL;
$fn = 'substr';
echo "I like {$fn('turtles!', 0, -1)}";
echo PHP_EOL;
echo PHP_EOL;
$escape = fn( $string ) => htmlspecialchars( (string) $string, ENT_QUOTES, 'utf-8' );
$userText = "<script>alert('xss')</script>";
echo "You entered {$escape( $userText )}";
echo PHP_EOL;
echo PHP_EOL;
class Arr
{
public static function get( $array, $key, $default = null )
{
return is_array( $array ) && array_key_exists( $key, $array )
? $array[$key]
: $default;
}
}
$fn = array( 'Arr', 'get' );
echo "I like {$fn(['turtles'], 0)}!";
- Output for 8.1.0 - 8.1.17, 8.2.0 - 8.2.11
- I like turtles!
I like turtles
You entered <script>alert('xss')</script>
I like turtles!
- Output for 8.0.1 - 8.0.28
- Parse error: syntax error, unexpected token ")" in /in/N3AR5 on line 4
Process exited with code 255.
preferences:
187.98 ms | 1399 KiB | 58 Q