PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: error
error - phponwebsites.com
Showing posts with label error. Show all posts

16 Jun 2014

4 Types of errors in php

                       Errors will occur for following reason in php:
                              1.unclosed quotes,
                              2.missing semicolon,
                              3.missing parentheses,
                              4.add extra parentheses,
                              5.unclosed braces,
                              6.undefined variable,
                              7.call undefined function,
                              8.includes files which is not found

Common errors in php:


                    Basically four types errors is occurred in php. There are:

                              1. Parse error
                              2. Fatal error
                              3. Warning
                              4. Noticed error

Parse error:

                       
                             The parse errors php is the syntax error. It stops the execution of the script in php. The common reasons for occur parse in php as follows:
                              1.unclosed quotes
                              2.missing semicolon
                              3.unclosed braces
                              4.missing parentheses
                              5.add extra parentheses

Parse error by unclosed quotes in php:

                               
                           Consider the following example in php:

<?php
          $name='guru;
          echo $name;
?>

       where, the quotes are not closed. When you run this file, you'll get error message like this:

parse error by missing quotes in php

Parse error by missing semicolon in php:

                                     Consider the following example:

<?php
     $name='Guru'
     echo $name;
?>

          where, the semicolon is missing at $name. It gives the parse error like below:

Parse error by missing semicolon in php

Parse error by unclosed braces in php:


<?php
 $a=5;
 $b=6;
 if($a==$b)
 {
   echo 'equal';
 else
 {
   echo'Not equal';
 }
?>

     where the closing brace is missed. When you run this file, you'll get error message like below:

parse error by missing braces in php

Fatal error in php:


                The fatal error will occur when you call the undefined function in php. It stop the execution of the php script.

<?php
 function name($str)
 {
  echo $str;
 }
  echo place('guru');
?>

            where the function "place()" is not defined. But you call that function. Now it gives the fatal error like below:

fatal error in php

Waring in php:


                       The warning is occurred when you include the file but the file is not found in php. It does not stop the execution of the php script.

<?php
 include('welcome.php');
 echo'welcome'; 
?>

       where, the file welcome.php is not found but you include it. So you'll get output like this:

warning error in php

Noticed error in php:


                   The noticed error is occurred when you use undefined variable. It does not stop execution of the php script.

<?php
 $name='Guru';
 echo $guru;
?>

       where $guru is not defined but you accessed. So you'll get error message like this:

Noticed error in php