PHP Special Types PHP

PHP Special Types  

PHP Special Types

PHP Special Types

There are 2 special data types in PHP

  1. Resource
  2. Null

Resource Data type:

It refers the external resources like database connection, FTP connection, file pointers, etc. In simple terms, a resource is a special variable which carrying a reference to an external resource.

Example 1

  1. <?php  
  2.     $conn = ftp_connect("127.0.0.1") or die("Could not connect");  
  3.     echo get_resource_type($conn);  
  4. ?>  

PHP Special Types

Example 2

  1. <?php  
  2.     $conn= ftp_connect("127.0.0.1") or die("could not connect");  
  3.     echo $conn;  
  4. ?>  

PHP Special Types

Example 3

  1. <?php  
  2.     $handle = fopen("tpoint.txt", "r");  
  3.     var_dump($handle);  
  4.     echo "<br>";  
  5.     $conn= ftp_connect("127.0.0.1") or die("could not connect");  
  6.     var_dump($conn);  
  7. ?>  

PHP Special Types


Null Data Type:

A variable of type Null is a variable without any data. In PHP, null is not a value, and we can consider it as a null variable based on 3 condition.

  1. If the variable is not set with any value.
  2. If the variable is set with a null value.
  3. If the value of the variable is unset.

Example 1

  1. <?php  
  2.        
  3.     $empty=null;  
  4. var_dump($empty);  
  5. ?>  

PHP Special Types

Example 2

  1. <?php  
  2.         $a1 = " ";  
  3.      var_dump($a1);  
  4.         echo "<br />";  
  5.         $a2 = null;  
  6.         var_dump($a2);  
  7. ?>  

PHP Special Types

Example 3

  1. <?php  
  2.     $x = NULL;  
  3.     var_dump($x);  
  4.     echo "<br>";  
  5.     $y = "Hello javatpoint!";  
  6.     $y = NULL;  
  7.     var_dump($y);  
  8. ?>  

PHP Special Types

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries