Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Using Anonymous Functions #3

Open
aubreypwd opened this issue Nov 29, 2013 · 0 comments
Open

Using Anonymous Functions #3

aubreypwd opened this issue Nov 29, 2013 · 0 comments

Comments

@aubreypwd
Copy link

This works:

$html = new phpHtmlWriter();
echo $html->tag('hr');
echo $html->tag('pre', gffd_debug_info() );

function gffd_debug_info(){
    return "String"
}

But, this does not:

$html = new phpHtmlWriter();
echo $html->tag('hr');
echo $html->tag('pre',
    function(){
        return "String"
    }       
);

Error I get:

Catchable fatal error: Object of class Closure could not be converted to string in .../php-html-writer/lib/phpHtmlWriterElement.php on line 50

Workaround that works using call_user_func:

$html = new phpHtmlWriter();
echo $html->tag('hr');
echo $html->tag('pre',
    call_user_func(
        function(){
            return "String"
        }
    )       
);

Not really sure if you can call an anonymous function like in the second example, so the workaround may be the only option. If there's not a way, you might want to consider including this in documentation?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant