Jump to content

most badass built-in php function


.josh

Recommended Posts

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.