Note that there are some explanatory texts on larger screens.

plurals
  1. POCode-Golf: one line PHP syntax
    primarykey
    data
    text
    <p><strong>Explanation</strong></p> <p>PHP has some holes in its' syntax and occasionally in development a programmer will step in them. This can lead to much frustration as these syntax holes seem to exist for no reason. For example, one can't easily create an array and access an arbitrary element of that array on the same line (<code>func1()[100]</code> is not valid PHP syntax). The workaround for this issue is to use a temporary variable and break the statement into two lines, but sometimes that can lead to very verbose, clunky code.</p> <p><strong>Challenge</strong></p> <p>I know of a few of these holes (I'm sure there are more). It is quite hard to even come up with a solution, let alone in a code-golf style. Winner is the person with in the least characters total for all four Syntax Holes.</p> <p><strong>Rules</strong></p> <ol> <li>Statement must be one line in this form: <code>$output = ...;</code>, where <code>...</code> doesn't contain any <code>;</code>'s.</li> <li>Only use standard library functions (no custom functions or <code>eval</code> allowed)</li> <li>Statement works identically to the assumed functional of the non-working syntax (even in cases that it fails).</li> <li>Statement must run without syntax error of any kind with <code>E_STRICT | E_ALL</code>.</li> </ol> <p><strong>Syntax Holes</strong></p> <ol> <li><code>$output = func_return_array()[$key];</code> - accessing an arbitrary offset (<code>string</code> or <code>integer</code>) of the returned array of a function</li> <li><code>$output = new {$class_base.$class_suffix}();</code> - arbitrary string concatenation being used to create a new class</li> <li><code>$output = {$func_base.$func_suffix}();</code> - arbitrary string concatenation being called as function</li> <li><code>$output = func_return_closure()();</code> - call a closure being returned from another function</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload