Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import libraries in PHP

Tags:

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 web 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.

like image 510
Tarik Avatar asked May 31 '11 18:05

Tarik


1 Answers

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();
 }
like image 125
dynamic Avatar answered Sep 21 '22 12:09

dynamic