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 6548651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:59:45+00:00 2026-05-25T11:59:45+00:00

like require class.a.php; require class.b.php; require class.c.php; class main{ function main(){ if(condition_is_met(){ $this->something =

  • 0

like

require "class.a.php";
require "class.b.php";
require "class.c.php";

class main{
 function main(){
   if(condition_is_met(){
      $this->something = new A();
   }else{
      $this->something = new B();
   }
 } 

}

Should the files be included in the condition check with require_once, and not all the time?

  • 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-05-25T11:59:46+00:00Added an answer on May 25, 2026 at 11:59 am

    The only performance it should effect is the time to parse it, but I think that is preferred over complicated include logic hidden midway inside of your file. Not to mention that if you put the require inside of the if statement it is like you inserted that file’s text inside of that if statement, which isn’t right (and may not work).

    Can anyone tell me if you can declare a class inside of a function/if statement?

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

Sidebar

Related Questions

I require a tree / directed acyclic graph implementation something like this: public class
Im trying to run something like this: <a href=login.php?logout=1 id=logout>logout</a> <div id=main> <?php require_once('getPhotos.php')
Is this a bad practice? like: function boo(){ require_once(class.moo.php); } ... ?
SOLVED: Error in template file I have Smarty setup like this: require_once 'smarty/Smarty.class.php'; $smarty
PHP manual suggests to autoload classes like function __autoload($class_name){ require_once(some_dir/.$class_name..php); } and this approach
So, I have a actions.class.php and have the function like that: public function executeGetHTML($request)
Here's what I'd like: Here's my code: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form
In ruby, if you use mechanize following 301/302 redirects like this require 'mechanize' m
I can't understand why this don't work. First i have a function like this
i've implemented this pagination class for search.php page in a separate file called class.pagination.php

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.