mcaskill/php-get-var-type

Get the type, resource name, or class name of a variable.

1.0.0 2016-11-01 15:54 UTC

This package is not auto-updated.

Last update: 2020-07-30 23:35:59 UTC


README

(PHP 5 >= 5.4)
get_var_type — Get the type, resource name, or class name of a variable.

Description

string get_var_type( mixed &$var )

Returns the type (name if an object or resource) of the PHP variable var.

Based on Pavel Lang's get_type() function.

Parameters

  • var — The variable being type checked.

Return Values

If the given var is:

  • a resource, this function will return the value from get_resource_type()
  • an object, this function will return the value from get_class()
  • else, this function will return the value from gettype()

Examples

Example #1 get_var_type() example

$data = array(1, 1., NULL, new ArrayIterator, 'foo', mysql_connect());

foreach ($data as $value) {
    echo gettype($value), "\n";
}

The above example will output something similar to:

integer
double
NULL
ArrayIterator
string
mysql link

Installation

With Composer

$ composer require mcaskill/php-get-var-type

Without Composer

Why are you not using composer? Download Function.Fallback.php from the gist and save the file into your project path somewhere.