SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 55 of 55
  1. #51
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mastodont View Post
    No doubt about it, but I talked about output parameters.
    Allow me to rephrase that; Parameters should be used for input, return values for output. If you need to return multiple values, then return an object or an array or consider splitting the function up.

  2. #52
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Allow me to rephrase that; Parameters should be used for input, return values for output. If you need to return multiple values, then return an object or an array or consider splitting the function up.
    Indeed. In the case of your parse function, you could either:
    PHP Code:
    list($component$action$lang) = parse($actualurl); 
    or

    PHP Code:
    $parser = new UrlParser($actualurl);
    $parser->component # etc... 
    Both of which I'd consider to be better than using output parameters

  3. #53
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    The only time I see where it is required/usable to use references where the function alters the original data is in the case of array_pop & array_shift.

    I see no other way to do it, take the first/last item from the array return it and still have it gone from the array. Well there is probably a way I just haven't figured out yet.
    This is clearly a case where it makes sense for arrays to be objects

  4. #54
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    For the curious my current Registry implementation.

    PHP Code:
            $path str_replace'_''/'$class );
            if ( 
    substr$path0) === 'cc' ) {
                
    $path 'CCentral/' substr$class);
            }

            if ( 
    class_exists$class ) ) {
                
    self::$_classname $class;
            } 
    You are using the registry as an autoload function.
    Not all classes must be declared as single instances (although not a bad idea). So it dublicates your autoload function.

  5. #55
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by REMIYA View Post
    You are using the registry as an autoload function.
    Not all classes must be declared as single instances (although not a bad idea). So it dublicates your autoload function.
    No that is incorrect. What it is for is to assign a default Registry storage implementation.

    if you extend ccRegistryStore and want to use that by default then you just need to do:
    PHP Code:
    Registry::setClassname'ccRegistryExtendedStore' );
    $r Registry::getInstance();

    var_dumpget_class$r ) );

    # or

    $r = new ccRegistryExtendedStore();
    Registry::setInstance$r ); 
    The setClassname method is incomplete at this time anyways. But I don't use __autoload.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •