Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    275
    Thanks
    39
    Thanked 0 Times in 0 Posts

    Can you do this with the include statement?

    Hi!

    Just curious because I didn't see anything in the doc about it but it's something that does make sense.

    And that thing is .. can you include just part of a file?

    Example: I have an include file that has some functions in it. Now I really don't need to include the entire file just a couple of functions.

    I ask because in my mainframe world the coding that we use to make jobs run you are allowed to include other files. In this case I can include the complete file or just specifying what lines I need.

    The file I'm including isn't that big, 3Kb. I'm just trying to satisfy my curiosity!

    BTW is there a rule of thumb on how you break up you php files? I know that you have a config file if applicable and one if you're using a database. Or is this just something user independent?

    Thanks for your help and insight!

    Sorry for any bad spelling, grammar and stuff that doesn't make sense. It's too early in the morning for me! =)
    “No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by MrBiggZ View Post
    can you include just part of a file?
    Not in an efficient way that would be worth the trouble. Technically, you could grab a few lines from a file and exec() them, but that's not worth the trouble.

    Quote Originally Posted by MrBiggZ View Post
    BTW is there a rule of thumb on how you break up you php files? I know that you have a config file if applicable and one if you're using a database. Or is this just something user independent?
    It just depends on how your application is structured. It's pretty common to just have a single config file on smaller applications, or a folder of config files in most of the larger frameworks. That makes the application pretty easy to move between environments, with all of the config changes centralized. It's also pretty common to have different config files for each environment if you have a multi-stage deployment process (Dev -> Staging -> QA -> Production) and use logic, such as checking the HTTP_HOST, to determine which config file to load for the current environment you are running the page on.

  • Users who have thanked Inigoesdr for this post:

    MrBiggZ (03-11-2013)

  • #3
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    275
    Thanks
    39
    Thanked 0 Times in 0 Posts
    Thanks!

    Plus I have to imaging that the code is in and out of memory pretty quick unless your like reading a database with a few million records in it.

    So in my case I'm not even going to worry about it!
    “No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.” ~ Mark Gibbs

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is one of those things that is near impossible to actually test, and my knowledge of the PHP source just isn't strong enough to verify for 100% certainty.
    I believe that during parse the engine only stores signature in symbols, and not the body. I base this off of two things, one being error triggering issued on call of a function, and the other being the behaviour of functions within functions.
    So if that logic holds its water, than the only real issue is that of time and not really the memory (it takes longer to go through a bigger file).

    As for splitting up, I'm mostly an OO programmer by this point in time. So I split them up file > class in order to make use of my spl_autoload_registers to chain with the namespace use calls. In procedural world, I'd do similar by collecting all functions based on their context use together. User manipulation functions in a file, post manipulation functions in a file, etc. And finally a generic one that is useful for anything (like date handling things, making 'pretty' byte displays, and so forth).
    So try to limit the things you don't need, but don't burden the script usage by splitting the functions up to be too fine grained. I wouldn't include a post handling function if I were editing a user, but I would include the same functions that let me edit a user's password for example even if I'm only editing a user's email address. So take what you *need* to use, plus what you *could* make use of.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    MrBiggZ (03-11-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •