File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 4
4
/**
5
5
* Generate a string of HTML attributes
6
6
*
7
- * @param array $attr Associative array of attribute names and values.
7
+ * @param array|object $attr Associative array or object of attribute names and values.
8
8
* @param callable|null $callback Callback function to escape values for HTML attributes.
9
9
* Defaults to `htmlspecialchars()`.
10
- * @return string Returns a string of HTML attributes.
10
+ * @return string Returns a string of HTML attributes
11
+ * or a empty string if $attr is invalid or empty.
11
12
*/
12
- function html_build_attributes (array $ attr , callable $ callback = null )
13
+ function html_build_attributes ($ attr , callable $ callback = null )
13
14
{
14
- if (!count ($ attr )) {
15
+ if (is_object ($ attr ) && !($ attr instanceof \Traversable)) {
16
+ $ attr = get_object_vars ($ attr );
17
+ }
18
+
19
+ if (!is_array ($ attr ) || !count ($ attr )) {
15
20
return '' ;
16
21
}
17
22
You can’t perform that action at this time.
0 commit comments