ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
PHP Tutorial - Index
PHP Tutorial - Introduction to PHP
PHP Tutorial - Your First PHP Script
PHP Tutorial - Operators
PHP Tutorial - Conditional and Looping
PHP Tutorial - Functions
PHP Tutorial - Classes and Objects
PHP Tutorial - Working with Forms
PHP Tutorial - Advanced PHP Topics
PHP Tutorial - Advanced Class Concepts
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > PHP Tutorial >Advanced PHP Topics
 

PHP Tutorial - Advanced PHP Topics

 
Page 2 of 2
 

Require

The require() statement includes and evaluates a specific file. The require() and include() statements are similar in every way except how they handle errors. When there is an error the include() statement produces a warning but the require() statement results in a fatal error. The require statement is used when you want a missing file to halt the processing of the page. In this case, if include() is used even then the script will keep on running regardless of the missing file.

Example

<?php

require 'welcome.php';

require $welcomefile;

require ('welcomefile.txt');

?>

 

Include

The include() statement includes and evaluates a specified file. The include() statement works in the same way as the require() statement. The basic difference between them is that when an error occurs the include() statement gives a warning whereas the require() statement gives a fatal error.

Example

fruit.php

<?php

$color = 'red';

$fruit = 'apple';

?>

test.php

<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A red apple

?>

 

Variable Functions

There is a concept of variable functions in PHP. The concept of variable function is that if a variable name has parentheses appended to it, then PHP will look for the function with the same name as the variable and will try to execute it. This can be used to implement callbacks and function tables.

Example

<?php

function fun() {

echo "In fun()<br />\n";

}

function abc

($arg = '')

{

echo "In abc(); argument was '$arg'.<br />\n";

}

// This is a wrapper function around echo

function echoit($string)

{

echo $string;

}

$func = 'fun';

$func(); // This calls fun()

$func = 'abc';

$func('test'); // This calls abc()

$func = 'echoit';

$func('test'); // This calls echoit()

?>

 

 

           

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.