#1
  1. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2006
    Posts
    1,986
    Rep Power
    533

    Static methods as complex variables doesn't work with heredoc


    I am using heredoc and complex variables on Linux PHP 5.3.18.

    The following script does not display the state options.

    If I replace {${library::get_options_sql('states')}} with {$options} and add $options=library::get_options_sql('states');, it does display the state options, so we know that the get_options_sql() method is fine.

    I do not, however, wish to define a variable for the options as my real example has about 20 variables, and my whole reason for doing this is to make the code cleaner.

    Any suggestions? Thanks

    PHP Code:
    echo(includes::location());

    class 
    includes {

        static public function 
    location()
        {
            return <<<DLIM
        <div id="dialog-location" title="Select a Location">
            <p class="validateTips">A location must be selected before saving.</p>
            <div>State:<select id="dl_states">
                    <option value="0">Select State</option>
                    
    {${library::get_options_sql('states')}}
                </select>
            </div>
            <div class="ui-widget">City:<input id="dl_city" data-cityID="" /></div>
            <div id="dl_zipcode_div">Zipcode:<select id="dl_zipcode"></select>
            </div>
        </div>
    DLIM;
        }

  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,053
    Rep Power
    9398
    You have to: it must be a variable or be a chained function call starting with a variable. Possibly other options I'm not thinking of but all of them require a variable.

    You are free to be creative, though...
    PHP Code:
    $call = function($method) {
        
    $args func_get_args();
        
    $method array_shift($args);
        return 
    call_user_func_array($method$args);
    }; 
    PHP Code:
    "{$call("library::get_options_sql""states")}
    Last edited by requinix; January 25th, 2013 at 12:37 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2006
    Posts
    1,986
    Rep Power
    533
    Thanks. I like your creative solution

IMN logo majestic logo threadwatch logo seochat tools logo