Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 152961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:43:00+00:00 2026-05-11T09:43:00+00:00

In PHP you have the create_function() function which creates a unique named lambda function

  • 0

In PHP you have the create_function() function which creates a unique named lambda function like this:

$myFunction = create_function('$foo', 'return $foo;'); $myFunction('bar'); //Returns bar 

Is this actually any better (apart from being more easy) then just doing:

do{  $myFunction = 'createdFunction_'.rand(); } while(function_exists($myFunction)); eval('function $myFunction(\$foo) { return \$foo; }'); $myFunction('bar'); //Returns bar 

Is create_function really better? (apart from the fact that it is more easy)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:43:00+00:00Added an answer on May 11, 2026 at 9:43 am

    On my understanding of the relevant docs,[1] they both do the same thing, create_function() just comes up with a unique function name for you.

    To address some other comments on this question:

    create_function can be assigned to a variable making the function accessible to other parts of your code, whereas eval is only useful for the given scope.

    It may well be that eval() runs in the current scope, but function definitions get dumped into the global namespace anyway.[2] So whenever you define a function, it will be accessible everywhere else in your program.

    Using eval() will clutter the global function list, create_function() will not

    create_function() only returns a string with the name of the new function,[3] not some special callback type. So, both techniques will pollute your global namespace.

    So no, apart from create_function() being easier, it does not appear to be any better than eval().

    Footnotes:

    [1] https://www.php.net/manual/en/functions.user-defined.php ; http://au.php.net/create_function ; http://au.php.net/eval

    [2] https://www.php.net/manual/en/functions.user-defined.php

    [3] http://au.php.net/create_function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The ways of handling it through .htaccess Rewrite can generate… May 11, 2026 at 6:17 pm
  • Editorial Team
    Editorial Team added an answer It most likely is just scraping the results from all… May 11, 2026 at 6:17 pm
  • Editorial Team
    Editorial Team added an answer I was able to find a workaround, but I still… May 11, 2026 at 6:17 pm

Related Questions

I asked this question before, Here however I think I presented the problem poorly,
My question is how does one abstract a database connection from the model layer
I have a web app I'm building that has about 50 forms. I have
I'll have an ASP.net page that creates some Excel Sheets and sends them to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.