News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Vance Lucas' Blog:
Get Only Public Class Properties for the Current Class in PHP
January 06, 2010 @ 10:06:29

On his blog today Vance Lucas has posted a method you can use to only get the properties of your class that are in the "public" scope.

PHP provides two built-in functions to retrieve properties of a given class '" get_object_vars and get_class_vars. Both these functions behave the same exact way, one taking an object as a variable and the other taking a string class name. The tricky thing about the two functions is that they behave differently depending on the call scope, returning all of the class variables available within the called scope.

As a bit of a hack (in lower than PHP 5.3) he shows how to use the create_function function to create a small statement in a different scope that returns the only the variables seen from the "outside" - just the public ones. PHP 5.3 users can do it much more cleanly with closures. Code examples for both are included.

0 comments voice your opinion now!
public class property createfunction closure tutorial


Sara Golemon's Blog:
create_function() is not your friend
May 21, 2007 @ 09:31:00

In response to this previous post from Felix Geisendorfer, Sara Golemon shares a few thoughts on why she thinks it's just the other way around - create_function is not your friend.

In the short post she lists just a few of the issues surrounding the use of the function including that it:

  • is prone to critical abuse by user-supplied code
  • skips opcode cache optimizations
  • encourages not using comments (evil)
  • 100% blind to reflection or PHPDoc style documentation generation

0 comments voice your opinion now!
createfunction eval abuse opcodecache reflection phpdoc createfunction eval abuse opcodecache reflection phpdoc


Felix Geisendorfer's Blog:
My new best friend - PHP's create_function()
May 18, 2007 @ 16:27:16

In a new post to his blog today, Felix Geisendorfer wants to introduce you to his new best friend in the wonderful world of PHP - the create_function function.

His name is 'create_function' and he's a really useful co-worker. For those of you who just vaguely know him - don't worry, he's not so much like his ev(a|i)l cousin. Well, that doesn't mean he can't be harmful, but he's more likely to help you instead.

To show why he's such a good friend, Felix includes some example code to help solve a fictional problem of a manager wanting to filter down the information about a few perspective programmers. The create_function function gives the code the ability to run various bits of code (like a call to in_array or counting the values in an array).

0 comments voice your opinion now!
createfunction example loop filter createfunction example loop filter


Metapundit.net:
Partial function application in PHP
February 14, 2007 @ 07:54:00

On the Metapundit.net site, there's a new (long) entry that takes a look at one of the programming styles, functional programming, and checks into its support in PHP. Unfortunately, it's mostly a swing and a miss.

I should just get this straight right off the bat: you can't really do much functional programing in PHP. Functions are not first class citizens and the equivalent of passing functions around is passing around strings or arrays and relying on convention. No really.

He goes on by illustrating the point that PHP can do this sort of thing but only up to a point. Once you start to get into anonymous functions and moving past things like the array_map function, you start to loose a foothold. The create_function function allows for a bit more flexibility, but still doesn't fulfill the requirements needed for full support.

0 comments voice your opinion now!
partial function application arraymap createfunction programming partial function application arraymap createfunction programming



Community Events





Don't see your event here?
Let us know!


framework release testing list introduction interview podcast series code unittest configure language refactor community laravel opinion threedevsandamaybe developer symfony2 install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework