Skip to content

Instantly share code, notes, and snippets.

@travisfont
Created August 11, 2015 15:56
Show Gist options
  • Select an option

  • Save travisfont/042e43651d9ddd447d48 to your computer and use it in GitHub Desktop.

Select an option

Save travisfont/042e43651d9ddd447d48 to your computer and use it in GitHub Desktop.
They said it's impossible in PHP, so here you go.. function's and condition statements inside a Heredoc in PHP. it's possible!
<?php
$result = function ($arg1 = false, $arg2 = false)
{
return 'function works';
};
$if = function ($condition, $true, $false) { return $condition ? $true : $false; };
// - ####################################
$set = <<<HTML
bal bal dasdas<br/>
sdadssa
HTML;
$empty = <<<HTML
data is empty
HTML;
$var = 'setting the variable';
// - ####################################
echo <<<HTML
<div style="padding-left: 34px; padding-bottom: 18px;font-size: 52px; color: #B0C218;">
{$if(isset($var), $set, $empty)}
<br/><br/>
{$result()}
</div>
HTML;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment