Questions tagged [require-once]

The PHP require_once function

The PHP require_once function.

In contrast to require this function only includes the referred file if it has not been included before.

Use this tag only for questions that directly ask about require_once usage. Do not use this tag if your code contains require_once but you have no reason to believe that require_once is directly related to the issue you are asking about.

409 questions
5
votes
1 answer

PHP Class finds Class file but not Class in the file

I've defined an abstract superclass in one file and a subclass in another. I have required the super-classes file and the stack trace reports to find an include it. However, it then returns an error when it hits the 'extends' line: Fatal error:…
Daniel Bingham
  • 12,414
  • 18
  • 67
  • 93
5
votes
3 answers

how to allow require_once() to php file in wordpress

I have a web site made by wordpress and I made some php files that i want to execute and for some reason I need to require_once(/wp-includes/class-phpass.php) but I got Failed opening required Error, there is a htaccess file in root folder and it…
Samad
  • 1,776
  • 2
  • 20
  • 35
5
votes
4 answers

How can I tune the PHP realpath cache?

Recent versions of PHP have a cache of filenames for knowing the real path of files, and require_once() and include_once() can take advantage of it. There's a value you can set in your php.ini to set the size of the cache, but I have no idea how to…
Andy Lester
  • 91,102
  • 13
  • 100
  • 152
4
votes
1 answer

"Fatal error: Cannot redeclare class" ... but the class was not declared

(I'm using Joomla v1.5.15 and PHP 5.3.4) I have tested the solutions found in this and others developer forums, but I still having the same error. Requiring file => contratolocal.php ... if ( !class_exists('MTIHelperEstadosLocal') ) …
guanchor
  • 97
  • 13
4
votes
3 answers

Why do people say require_once is slower than require?

Possible Duplicate: Why is require_once so bad to use? When PHP is including a file I assume it stores the file name inside a array. Then, when including another file, it will check that array to see if it's already included, right? So what's…
Amanda
  • 51
  • 1
  • 3
4
votes
1 answer

What are the Advantages and Disadvantages of conditionally including a class file with in a method of another class in PHP?

In this question about including all the classes in a directory for an interpreter that needs all of them, it was suggested that a better way to handle the problem would be to conditionally include only the Command file that is needed for this…
Daniel Bingham
  • 12,414
  • 18
  • 67
  • 93
4
votes
3 answers

Is it worth using require_once() for memory savings?

I'd like to check if my understanding's correct about require_once(). I have a bunch of functions in file foo.php. Let's say 7/8 out of them are always used, and one of them's rather rare and rather large. I have to keep this function's definition…
Jes
  • 65
  • 2
4
votes
6 answers

How can I speed up a 1800-line PHP include? It's slowing my pageload down to 10sec/view

I designed my code to put all important functions in a single PHP file that's now 1800 lines long. I call it in other PHP files--AJAX processors, for example--with a simple "require_once("codeBank.php")". I'm discovering that it takes about 10…
4
votes
3 answers

How to implement a class using namespaces in PHP

I am having trouble implementing a particular class in PHP. I want to use Anthony Ferrara's RandomLib library in my Zend Framework application (you can find it here.) I've been programming in PHP for a few years now, so I know my way around it for…
blainarmstrong
  • 1,040
  • 1
  • 13
  • 33
4
votes
2 answers

How to require_once from different directories?

I am trying to require my "library" files from php files in different folders, but it gives errors when trying to access them from a subfolder. For example I have such a directory: + home - file1.php ++ subfolder - file2.php ++ libraries …
marvin
  • 365
  • 3
  • 7
  • 22
4
votes
3 answers

A practical scenario for using include(), include_once() and require() constructs

Among include, include_once, require and require_once I always just use require_once. Many third-party frameworks just use require_once as well. Can anybody please describe a real scenario that another construct must be used?
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
4
votes
1 answer

Force php to look at Document Root

So I was messing around with the twitter api, and I want to include this file in the footer for every page. The footer is loaded via phps require_once function. The problem is I can't use a full url because of url file acsess being turned off for…
Tyler Radlick
  • 184
  • 1
  • 6
  • 12
3
votes
4 answers

Variable in php require_once file path

How do you take the following and substitue part of the file path as a variable? require_once $_SERVER['DOCUMENT_ROOT'] . '/directory1/directory2/directory3/file.php'; I want to substiture directory2 with a variable $dir2. Simply inserting the…
martin
  • 393
  • 1
  • 6
  • 21
3
votes
4 answers

Using require_once inside a method

From what I understand using something like require_once will essentially copy and paste the code from one file into another, as if it was in the first file originally. Meaning if I was to do something like this it would be…
Amit Shah
  • 4,176
  • 2
  • 22
  • 26
3
votes
2 answers

php include file that has includes

I am working on a site and have been asked to include files that are sitting in a folder above my php scripts. Problem is those php files I have been asked to include, have includes in them. And thus the files they refer to cannot be found when…
user1157576
  • 47
  • 1
  • 3
1 2
3
27 28