SitePoint Sponsor

User Tag List

Page 4 of 4 FirstFirst 1234
Results 76 to 84 of 84
  1. #76
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Brooklyn, NY
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I encourage you to subscribe to the mailing list if you run into any problems:

    fw-general-subscribe@lists.zend.com

    Thanks very much for the help, akrabat. I think the docs for Zend_Controller got left out of the manual when it was built, so hopefully that will be taken care of as soon as Zend wakes up. :-)

    (It's 7:45 AM there, and they've been working around the clock for the past few days.)
    Chris Shiflett
    http://shiflett.org/

  2. #77
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, already got a prompt response from Andi regarding a possible problem with ZSearch

  3. #78
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shiflett
    I encourage you to subscribe to the mailing list if you run into any problems:

    fw-general-subscribe@lists.zend.com
    Done. Archive page?

  4. #79
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zend_Db_DataObject appears to be documented, but not released?

  5. #80
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    Worcester
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Selkirk
    Done. Archive page?
    Hopefully something they'll sort out when the do the svn access....

  6. #81
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP 5 compatible backtrace hack returns calling class from static methods

    Here's a working backtrace hack for PHP 5: (thanks for Ren's tip on Joshua Eichorn's blog)

    You can make a global function if you like:
    PHP Code:
    // Find the calling class from within a static method.
    function get_calling_class() {
        
    $trace debug_backtrace();
        
    $lines file($trace[1]['file']);
        
    $line $lines[$trace[1]['line'] -1];
        
    preg_match('@[a-z_][a-z0-9_]*(?=::' $trace[1]['function'] . ')@i'$line$matches);

        return 
    $matches[0];

    Now you can use it from any static method:

    PHP Code:
    class MyParent {
        public static function 
    parentMethod() {
            
    $callingClass get_calling_class();
            echo 
    "Calling class: $callingClass\n";
        }
    }

    class 
    Kiddo extends MyParent {
    }

    Kiddo::parentMethod();
    // returns "Calling class: Kiddo" 
    Last edited by Trent Reimer; Aug 24, 2006 at 19:29. Reason: remove redundant arguments

  7. #82
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will only work if there's only a single static call on the line; if there are more than one, it will always return the first one...

  8. #83
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 33degrees
    That will only work if there's only a single static call on the line; if there are more than one, it will always return the first one...
    Hmm, thanks for pointing that out. How about something like this?
    PHP Code:
    function get_calling_class() {
        
    $trace debug_backtrace();
        for (
    $i 1$i count($trace); $i ++) {
            
    $item $trace[$i];
            if (isset(
    $trace[$i 1]['class']) && get_parent_class($trace[$i 1]['class']) == $item['class']) {
                continue;
            } else {
                break;
            }
        }
        
    $lines file($item['file']);
        
    $line $lines[$item['line'] -1];
        
    preg_match('@[a-z_][a-z0-9_]*(?=::' $item['function'] . ')@i'$line$matches);

        return 
    $matches[0];

    Seems to test with something like:
    PHP Code:
    class Pappa {
        function 
    nameCallingChild() {
            echo 
    get_calling_class();
        }
    }

    class 
    SonnyBoy extends Pappa {
        function 
    nameCallingGrandChild() {
            return 
    parent::nameCallingChild();
        }
    }

    class 
    Grandson extends SonnyBoy {
    }

    class 
    BigThing {
    }

    class 
    Thing extends BigThing {
        function 
    doThing() {
            
    Grandson::nameCallingGrandChild();
        }
        function 
    doOtherThing() {
            
    Grandson::nameCallingChild();
        }
    }

    $obj = new Thing();
    $obj->doThing();
    // echos "Grandson"
    $obj->doOtherThing();
    // echos "Grandson" 

  9. #84
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another obstacle; this hack only matches direct class::method calls. It doesn't work with call_user_func_array.

    PHP Code:
    class Poppa {
        var 
    $setting='hello';

        function 
    do_thing() {
            
    $kid get_calling_class();
            
    $obj = new $kid;
            return 
    call_user_func_array(array($obj'do_kid_thing'), null);
        }

        function 
    do_kid_thing() {
            echo 
    $this->setting "\n";
        }

        function 
    do_thing_with_array() {
            
    call_user_func_array(array(get_calling_class(), 'do_thing'), null);
        }
    }

    class 
    Kid extends Poppa {
        var 
    $setting 'hi';
    }

    Kid::do_thing();
    # returns 'hi' as anticipated
    Kid::do_thing_with_array();
    # triggers error 
    Extending the hack to work with call_user_func_array is just too ugly to even consider. Sigh.


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
  •