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

  • SEARCH
  • Home
  • 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 8350147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:13:32+00:00 2026-06-09T08:13:32+00:00

Sometimes I need to create PHP code for formatting arrays on the fly. one

  • 0

Sometimes I need to create PHP code for formatting arrays on the fly. one way to do this is to use eval. but I think of writing the generated code to a PHP file and then include it. This has many advantages to eval, one of them is caching of generated code. But I haven’t seen such a practice in other code. I don’t know if there’s any problem regarding security or other things with this?

This is an example:

<?php

$code = '<? foreach($rows as $row) {$row["insertion"] = format($row["insertion"]);} ?>'
file_put_contents('formatter.php', $code);
include('formatter.php');

?>

I just want to know is it good to create a PHP file on the fly and then include it?

Or is it better to just go ahead and eval() the code directly, with no stored history?

  • 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. Editorial Team
    Editorial Team
    2026-06-09T08:13:34+00:00Added an answer on June 9, 2026 at 8:13 am

    If you have to create code dynamically, it is always more efficient and usually more secure to dump the output into a file and then include it. Then you only have to do this once per piece of code and it allows for opcodes caching (via APC and the like) and more efficient preprocessing by the Zend Core engine. ANother benefit is that you can debug included files, while debugging eval()ed statements is rarely supported.

    The reason it is more secure to store it into a file is that then you have a record of what was run; with eval(), it’s more or less a black box and you have no idea what’s been executing. Additionally, you should be able to lock down the writes folder to where only a certain app can write to it. If you separate your dynamic array creation logic from your main app, and then include the file via your main app itself, this will undoubtedly increase security and performance, assuming you’ve made the temp files read-only to Apache and writeable only by the PHP app (doable via cron, among other methods).

    There’s possibly a better solution for what you’re doing (like memcache or APC fetch/store) but I have run into similar circumstances that largely benefited from the including stuff (for instance, tweaking smarty templates to be included rather than eval’d worked amazingly).

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

Sidebar

Related Questions

In web design I use MVC pattern, but sometimes I need to create non-web
In my code, I create a link like this: $link = 'http://www.mydomain.com/'.urlencode($str).'/1'; I use
I use TXMLDocument to create XML documents. Sometimes I need to change attribute values.
Sometimes you need to create a very simple single file application in Qt4. However
Sometimes in Salesforce tests you need to create User objects to run part of
I sometimes need to look for information for a special portion of code. When
Possible Duplicate: Grouping WHERE clauses with Zend_Db_Table_Abstract I need to create something like this:
I make use of session_set_save_handler(). It works fine. However, sometimes I need to alter
In Codeigniter, when we use $this->load('class_name') in the controller, CI will try to create
in my WPF application I sometimes need to create a small helper window and

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.