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

Tomas Votruba:
Function create_function() is Deprecated in PHP 7.2 - How to Migrate?
Dec 18, 2018 @ 15:34:16

In this post to his site Tomas Votruba covers the create_function function, its deprecation in PHP 7.2 and how to refactor your code to remove it.

If there would be "Miss Deprecation of PHP 7.2", create_function() would definitely win. They can be very complex, tricky and very hard convert to PHP code. Moreover without tests.

Do you have over 5 create_function() pieces in your code? Let's see how to migrate them.

He starts by talking about why it's being deprecated (it's essentially an eval) and some examples of how it could be used to execute code. He then goes through several usage examples and shows how to refactor them into anonymous functions. In his examples he uses a mix of regular code conversions and a sort of hybrid using strings and code to replace the string (probably) used previously with create_function.

tagged: createfunction function deprecation anonymous tutorial refactor

Link: https://www.tomasvotruba.cz/blog/2018/12/17/function-create-function-is-deprecated-in-php-72-how-to-migrate/

Vance Lucas' Blog:
Get Only Public Class Properties for the Current Class in PHP
Jan 06, 2010 @ 16: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.

tagged: public class property createfunction closure tutorial

Link:

Sara Golemon's Blog:
create_function() is not your friend
May 21, 2007 @ 14: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

tagged: createfunction eval abuse opcodecache reflection phpdoc createfunction eval abuse opcodecache reflection phpdoc

Link:

Sara Golemon's Blog:
create_function() is not your friend
May 21, 2007 @ 14: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

tagged: createfunction eval abuse opcodecache reflection phpdoc createfunction eval abuse opcodecache reflection phpdoc

Link:

Felix Geisendorfer's Blog:
My new best friend - PHP's create_function()
May 18, 2007 @ 21: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).

tagged: createfunction example loop filter createfunction example loop filter

Link:

Felix Geisendorfer's Blog:
My new best friend - PHP's create_function()
May 18, 2007 @ 21: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).

tagged: createfunction example loop filter createfunction example loop filter

Link:

Metapundit.net:
Partial function application in PHP
Feb 14, 2007 @ 13: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.

tagged: partial function application arraymap createfunction programming partial function application arraymap createfunction programming

Link:

Metapundit.net:
Partial function application in PHP
Feb 14, 2007 @ 13: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.

tagged: partial function application arraymap createfunction programming partial function application arraymap createfunction programming

Link:


Trending Topics: