Last active
December 17, 2015 07:48
-
-
Save Trainmaster/5575151 to your computer and use it in GitHub Desktop.
Behaviour of htmlspecialchars() (or any other string function?) when passing arguments with different types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'foo'; | |
var_dump(htmlspecialchars($string)); | |
// string(3) "foo" | |
$integer = 1; | |
var_dump(htmlspecialchars($integer)); | |
// string(1) "1" | |
$float = 1.2; | |
var_dump(htmlspecialchars($float)); | |
// string(3) "1.2" | |
$boolean = true; | |
var_dump(htmlspecialchars($boolean)); | |
// string(1) "1" | |
class Foo | |
{ | |
public function __toString() | |
{ | |
return 'Foo'; | |
} | |
} | |
$foo = new Foo; | |
var_dump(htmlspecialchars($foo)); | |
// string(3) "Foo" | |
$null = null; | |
var_dump(htmlspecialchars($null)); | |
// string(0) "" | |
$object = new StdClass; | |
var_dump(htmlspecialchars($object)); | |
// Warning: htmlspecialchars() expects parameter 1 to be string, object given | |
// NULL | |
$array = array(); | |
var_dump(htmlspecialchars($array)); | |
// Warning: htmlspecialchars() expects parameter 1 to be string, array given | |
// NULL | |
$array = (string) array(); | |
var_dump(htmlspecialchars($array)); | |
// string(5) "Array" | |
print array(); | |
// Array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment