My Life with PHP
  • Decleration style tag of php:

  • Php is providing different types of decleration style tags

    1. Universal style tag:

        This tag supports all functionality

      <?php 
       ## code 
          .........
          .........
      ?>
    2. Short open tag:

        This tag supports very few functionality

      <?
       ## code 
          .........
          .........
      ?>
    3. ASP style tag:

        We can add php script with in asp decleration syntax

      <%
       ## code 
           .........
           .........
      %>
    4. Script style tag:

        It is similar to java script decleration syntax

      <script language="php">
       ## code 
          .........
          .........
      <script>

      We have 2 configuration settings in php in related to decleration style tag the default value is OFF for short open tags & asp tags. by changing the value we can execute this tag. we need to restart the server to see the changes.

  • Output functions in php:

  1. Print:

      This function displays output on browser & return a boolean value "TRUE", if output is printed successfully, otherwise "FALSE". We can't print multiple statements with single print statement.
    [Note:In php value of TRUE is "1" and FALSE means "no value"]

    Example:-
    <?php 
        $a=print "abc";
        print "<br>";
        print $a;
    ?>
  2. Echo:

     It is same as print function.But we can print multiple statements, with a single echo function.
    The function doesn't return any value,that's why faster than print

    Example:-
    <?php 
        echo "abc", "def";
    ?>

2.VAR-DUMP:

This function display variable along with its datatype.

Example:
 
 <?php
 $sno=111;
 var-dump($sno);
 >?

3.printf:

By using this function ,we can display output with the help of format specification.

Example:
 
 <?php
 $a=10;
 $user="scott";
 printf("%5 has %d cars,$a,$user")
 >?

4.printr:

By using this function we can display all elements of array and properly of object.

TYPES OF ERRORS IN PHP


There are 4 four types of errors.

1.Notice:

It is nothing but a small information to user .if we are trying to access undefined variables.the output is "Notice".
Notice doesn't stop a script execution.

<?php
 $x=100;
 echo$a;
 echo$y;
 ?>
 
output:
Notice

By default we cannot see the notice message on browser. Because, the configuration setting i.e error reporting value is "E_all".&NE_NOTICE means display all error messages except Notice.by remaining NE_NOTICE ,the notice are displayed by the browser. we can also display Notice within the prog by using error reporting(E_ALL);

<?php
 $x=100;
 echo$x;
 echo$y;
 echo"NEXT";
 ?>

2.warning:

It is same as notice doesn't stop script execution. if occurs if we are trying to call undefined constants.
in php ,we can declare constant by using define.

<?php
define("sno,20");
echo constant("sno");
echo constant("a");                                           
?>

3.Fatal Error:

It stops the execution of web page, from line where the error occured.if we try to call undefined function fatal error occurs.

<?php
define("sno,20");
echo constant("sno");
echo constant("a");                                           
?>

4.Parse Error:

It stops the execution of complete script if there syntax mismatch.

Example:
<?php
echo"line";
echo"12";
echo"13";                                           
?>

Notice:
If the last line doesn't contain a semicolon ,no error occures.