Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 847903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:51:44+00:00 2026-05-15T06:51:44+00:00

Explanation PHP has some holes in its’ syntax and occasionally in development a programmer

  • 0

Explanation

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 (func1()[100] 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.

Challenge

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.

Rules

  1. Statement must be one line in this form: $output = ...;, where ... doesn’t contain any ;‘s.
  2. Only use standard library functions (no custom functions or eval allowed)
  3. Statement works identically to the assumed functional of the non-working syntax (even in cases that it fails).
  4. Statement must run without syntax error of any kind with E_STRICT | E_ALL.

Syntax Holes

  1. $output = func_return_array()[$key]; – accessing an arbitrary offset (string or integer) of the returned array of a function
  2. $output = new {$class_base.$class_suffix}(); – arbitrary string concatenation being used to create a new class
  3. $output = {$func_base.$func_suffix}(); – arbitrary string concatenation being called as function
  4. $output = func_return_closure()(); – call a closure being returned from another function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:51:44+00:00Added an answer on May 15, 2026 at 6:51 am

    The only solution I see involves a temporary variable, so there is some (minimal) namespace pollution. Any way of tightening the temporary variable code would shorten all 4 of these:

    <?php
    
    error_reporting(E_ALL | E_STRICT);
    
    // 1
    function func_return_array() { return array(0 => 'hello'); }
    $key = 0;
    
    $output = ${!${''}=func_return_array()}[$key];
    
    echo '1: ' . $output . "\n";
    
    
    // 2
    class Thing {}
    $class_base = 'Thi'; $class_suffix = 'ng';
    
    $output = new ${!${''}=$class_base.$class_suffix}();
    
    echo '2: ';
    var_dump($output);
    
    
    // 3
    $func_base = 'func_'; $func_suffix = 'return_array';
    
    $output = ${!${''}=$func_base.$func_suffix}();
    
    echo '3: ';
    var_dump($output);
    
    
    // 4
    function func_return_closure() {
        return function() {
            return 'This is a closure';
        };
    }
    
    $output = ${!${''}=func_return_closure()}();
    
    echo '4: ';
    var_dump($output);
    

    Output:

    1: hello
    2: object(Thing)#1 (0) {
    }
    3: array(1) {
      [0]=>
      string(5) "hello"
    }
    4: string(17) "This is a closure"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PHP an Associative Array keeps its order. // this will keep its order
This will take a bit of explanation so I hope I don't lose everyone
I can´t find an explanation to this behaviour (SQL Server 2008 + PHP 5.2.14)
I have read the PHP manual , but couldn't find any proper explanation regarding
Explanation: i have few objects and im declaring them inside $(document).ready(). WHY? because in
Short explanation of my problem, I need to parse an object and put its
I maintain an application that uses a (to me) surprising PHP quirk/bug/feature. Consider this
I'm an iOS developer who has only passing knowledge of front-end web development, but
How do you do a regex in php that finds a space that has
I have some PHP source code that I'm hosting with hosting company XYZ. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.