-2

i want to create a php file where all functions are define for my project but i don't want to include that file to every single file of my php project. i want to create all function inside that php file global so can call them in that directory. just like wordpress.

like they define most of function inside wp-include/pluggable.php which included in wp-setting.php and finally that include in wp-config.php file but i am not able to figure it out how they make that function global for theme and plugin without include it.

thanks in advance

NikiC
  • 100,734
  • 37
  • 191
  • 225
Corlax
  • 724
  • 1
  • 8
  • 25
  • that not my question please read it again i know how to include a function but i want to create a global function for all files without include it and found my solution below. – Corlax Jun 22 '14 at 12:41

1 Answers1

1

You can't create global function without including the file where you defined them. In the case of WP, the file may be included by a dependency but you can be sure it's included somewhere :)

Two way to include your file :

  1. Using php native function in all your files : http://www.php.net//manual/fr/function.include.php
  2. Using PSR standard : http://www.php-fig.org/psr/psr-0/

Use the PSR standard if you can.

Kevin Labécot
  • 2,005
  • 13
  • 25
  • 1
    @KevinLabécot You can call any function using the `use` keyword. ex: `use path/to/function/foo()` – samayo Jun 22 '14 at 12:37