Jump to content

most badass built-in php function


.josh

Recommended Posts

In you opinion, what do you think  is the most "badass" built-in php function? Like..."Holy shit I didn't know there was something out there for xyz, I somehow feel like I just learned a new kung-fu move! <swipe hands in air pretending you really know kung-fu>"

Link to comment
https://forums.phpfreaks.com/topic/177485-most-badass-built-in-php-function/
Share on other sites

Hmm.. that's a tough one.. I agree with corbin mentioning PCRE... but once you learn it, it's old hat (much like anything else I suppose).

For me, as of late, it's not so much about something built-in that blows my socks off or anything, but nice to know ones:

 

The Reflection API offers built-in classes that provide a nice way to 'reverse engineer' objects to see what they are comprised of (something I have only started making use of as of late - I know, I'm late to the reflection party so to speak).

 

I'm digging PHP 5.3's closures (a closure is a 'kind of anonymous' function that can be stored as a variable and is contextual with regards to variables involved).

 

Simple example:

$x = 2;
$addStuff = function() use ($x){
    $args = func_get_args(); // get unknown list of function() parameters (if no params are present, $arg will be set yet empty)
    if(count($args)){
foreach($args as &$val){
    $val += $x;
}
return $args;
    } else {
echo 'No values passed into function()';
    }
};

$arr = $addStuff(3,7); // you can add or remove parameters here and function() will be flexible
echo '<pre>'.print_r($arr, true);

 

EDIT - the flexible part of parameters is not due to function() itself, as this can be done with a regular function..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.