panique / mini

Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)
1.35k stars 479 forks source link

[suggestion] Using array_shift to get url params #162

Closed abaracedo closed 9 years ago

abaracedo commented 9 years ago

Well, i just downloaded the project and i looked the code and i saw that to get url params it checks if the values are set, maybe another option to get the params from url is using array_shift:

        $url = explode('/', $url);
        // Put URL parts into according properties
        // By the way, the syntax here is just a short form of if/else, called "Ternary Operators"
        // @see http://davidwalsh.name/php-shorthand-if-else-ternary-operators
        $this->url_controller = array_shift($url);
        $this->url_action = array_shift($url);

        // Rebase array keys and store the URL params
        $this->url_params = array_values($url);
panique commented 9 years ago

Thanks a lot, very interesting! Didn't even know that this functions exists! Have you tested this already ? Is it save to use when the array is empty etc. ?

abaracedo commented 9 years ago

I didn't try because i'm trying to set the project working (having problems) but array_shift returns null if the array is empty or it is not an array.

panique commented 9 years ago

There's a fail-safe tutorial in the readme and also a one-line installer for Vagrant btw.

panique commented 9 years ago

He, I'll reject this as array_shift is a writing operation and much slower that simply reading the url params. But thanks anyway!