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

snippet
<?php
	$conn = ftp_connect("127.0.0.1") or die("Could not connect");
	echo get_resource_type($conn);
?>
PHP Special Types

Example 2

snippet
<?php
	$conn= ftp_connect("127.0.0.1") or die("could not connect");
	echo $conn;
?>
PHP Special Types

Example 3

snippet
<?php
	$handle = fopen("tpoint.txt", "r");
	var_dump($handle);
	echo "<br>";
	$conn= ftp_connect("127.0.0.1") or die("could not connect");
	var_dump($conn);
?>
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

snippet
<?php
	 
	$empty=null;
var_dump($empty);
?>
PHP Special Types

Example 2

snippet
<?php
    	$a1 = " ";
   	 var_dump($a1);
    	echo "<br />";
    	$a2 = null;
    	var_dump($a2);
?>
PHP Special Types

Example 3

snippet
<?php
	$x = NULL;
	var_dump($x);
	echo "<br>";
	$y = "Hello rookienerd!";
	$y = NULL;
	var_dump($y);
?>
PHP Special Types
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +