Require and include

Asked

Viewed 283 times

3

Hello I’m having a doubt on the following:

Class: "Teste1.php"

<?php
class Teste1{}...
?>
  • Ex1-include 'Teste1.php'
  • Ex2- include_once 'teste1.php'
  • Ex3- require_once 'Teste1.php'

Is it possible to call teste1 (in minuscule), as in Ex2? It will work?

I saw in some blogs that is only in php 4, from there is not correct for being case sensitive, this certain?

Thank you

2 answers

2

In file systems case-insensitive, as is the case with Windows, it makes no difference. However, Linux is case-sensitive!

In my own experience, I used the files with the tiny names and the Autoloader with PSR-4 loaded my files normally using even PHP 7.2 (Current). However, when running my project on Linux, also with PHP 7.2, I had to rename my files attentive to case-sensitive.

The ideal is to include files always attentive to upper and lower case letters, since it is possible to change environments over time.

1

It works that way:

<?php
include_once "a.php"; // vai carregar o ficheiro a.php
include_once "A.php"; // vai carregar o ficheiro a.php novamente! (só no PHP4)
?>

This behavior has changed in PHP5. That is, the file is loaded only once.

source: http://php.net/manual/en/function.include-once.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.