Tarik Tarik - 4 months ago 7
PHP Question

How to import libraries in PHP

I am normally an Asp.NET developer who wants to migrate to PHP. I am taking quite a time to learn it and I am wondering how to use libraries in PHP?

Do I need to use

require
or
include
to import a library into my project to use the
classes
,
functions
etc. defined in the library? Or something else.

I running php on the apache server what I've found is for Zend Server and it looked weird to me.

Can someone explain me overall steps to import and start using libraries in my own code?

Thanks.

Answer

You can use both.

Require will throw a fatal error if the file is not found.

require('lib.class.php');

You could use include if you need to continue the script even if the file couldn't get loaded.

Like:

 if (!include('lib')) {
   doWhatever();
 }
Comments