Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17
Like Tree6Likes

Thread: Cannot Redeclare Function() (previously declared in......) in ....... on line 15

  1. #11
    Administrator Frinkky's Avatar
    Join Date
    Dec 2008
    Posts
    1,817
    Blog Entries
    1

    Default 13 Jan 2012 @ 14.07

    In that you should replace ALL require()'s with require_once() in all files, not just in index.php. If you import a file with 'include_once' or 'require_once' then try to 'include' or 'require' it again afterwards, you don't get the benefit of php checking if the file is already present.
      Reply With Quote

  2. #12
    New Registered User Shahlin's Avatar
    Join Date
    Aug 2011
    Posts
    35

    Default 13 Jan 2012 @ 14.11

    Thanks Alot! For The Info.
      Reply With Quote

  3. #13
    New Registered User Shahlin's Avatar
    Join Date
    Aug 2011
    Posts
    35

    Default 13 Jan 2012 @ 14.14

    I Tried It!!!
    And it works perfectly!!!!!
    THANKS ALOT!
      Reply With Quote

  4. #14
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 13 Jan 2012 @ 15.48

    include_once and require_once are one solution, but not the optimal solution because they cause a large performance hit. The best solution would be to sort out your file inclusion logic. Maybe do all includes in one file and only include that file from your other content pages....

    Were you including core.php from config.php? That also could have caused the error...
    Shahlin likes this.
      Reply With Quote

  5. #15
    Administrator Frinkky's Avatar
    Join Date
    Dec 2008
    Posts
    1,817
    Blog Entries
    1

    Default 13 Jan 2012 @ 16.42

    Ah, I understood *_once performance to be a non-issue these days (ref: php - Why is require_once so bad to use? - Stack Overflow) but having never specifically tested I was taking the general tone of that SO thread as proof.

    So what you're saying is to 'include' one file that 'include's everything else - what's to stop the main include file being called again and therefore triggering a redeclare error?
      Reply With Quote

  6. #16
    New Registered User Shahlin's Avatar
    Join Date
    Aug 2011
    Posts
    35

    Default 14 Jan 2012 @ 04.50

    Oh! Ok Thanks!

    No i wasn't. I had all my functions in core.php and the mysql_connect in config.php. I'll Try Doing What You Said! :D
      Reply With Quote

  7. #17
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 16 Jan 2012 @ 09.31

    quote
    Ah, I understood *_once performance to be a non-issue these days (ref: php - Why is require_once so bad to use? - Stack Overflow) but having never specifically tested I was taking the general tone of that SO thread as proof.
    Originally Posted by Frinkky View Post
    In smaller applications it really isn't a "valid" performance problem as you're mostly only including a couple files. But, consider a larger application with a couple hundred includes and complex auto-loading routines, suddenly you're going to start noticing it. Now add a decent amount of traffic, you're probably going to need load-balanced front ends which are probably going to have an NFS mount (big delay in file read times) and suddenly every millisecond is critical. Just because it isn't "necessary" to follow best practice rules doesn't mean you shouldn't do it. Why promote bad habits....? </pet peeve rant> :D

    quote
    So what you're saying is to 'include' one file that 'include's everything else - what's to stop the main include file being called again and therefore triggering a redeclare error?
    Originally Posted by Frinkky View Post
    Your application logic. Most applications these days follow some kind of MVC architecture. And all the major frameworks use a main/front controller (single point of entry) which handles all initialization and includes. There are very, very few exceptions where this kind of architecture does not work.... Any other type of architecture will involve duplicate code and will not be lovely & shiny & object oriented :D
    Frinkky and Shahlin like this.
      Reply With Quote

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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