+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 18 of 18
  1. #16
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,442
    How about
    PHP Code:
    static $closure null;
    if(!isset(
    $closure)) { 
    ?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  2. #17
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    711
    tried that earlier; no significant effect on execution time. I guess static is the expensive part.

  3. #18
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,442
    I think both that and the test hold things up.
    PHP Code:
    <?php
    function closureTest(){
    //    static $closure = null;
    //    if(!isset($closure))
        
    $closure = function(){ return "something\n"; };
         return 
    $closure();
    }
    From my own timings (static vs. nonstatic, checked vs. nonchecked) enabling both or neither are roughly the same, and are significantly better than doing only one.

    Then again, how does
    PHP Code:
    function closure()
    {
        return 
    "something\n";
    }

    function 
    closureTest(){
        print 
    closure();
    }

    closureTest();
    closureTest();
    closureTest(); 
    perform? My point being, that a main strength of closures is that they "close over" variables in their defining scope, so that you can customise the function on the fly. If it has the same body every time you create it you might as well just make it an ordinary function - one with a name that you can refer to it by.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts