PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] How are include_once loops handled in php?

 July 22, 2022     php, php-5.3, php-5.4     No comments   

Issue

I have 3 different files-

  1. fileMainIncludeEverywhere.php

    ...
    include_once('fileMinorInclude.php');
    ?>
    
  2. fileMinorInclude.php

    ...
    include_once('fileMainIncludeEverywhere.php');
    ...
    
  3. fileToRun.php

    ...
    include_once('fileMainIncludeEverywhere.php');
    ...
    

I have a lot of files like fileToRun.php.

Currently I'm not facing any errors in my code, but I want to know if there's any case where this would fail?


Solution

I think no error in this case. Because include_once will only load the file for the first time then upcoming load request will be rejected for the same file.

So from your example:

  1. fileToRun.php will load fileMainIncludeEverywhere.php (first call)
  2. fileMainIncludeEverywhere.php will load fileMinorInclude.php (first call)
  3. fileMinorInclude.php will call to load fileMainIncludeEverywhere.php but it will be rejected as it has been already loaded in first step.

Hope it will help.



Answered By - d.coder
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing