PHP Classes

How to Get the Names of All Data Types Using the PHP Type Class: Get the names of each basic PHP data type

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 68 All time: 10,325 This week: 660Up
Version License PHP version Categories
php-type-names 1.0.0GNU General Publi...7.3PHP 5, Data types, Language
Description 

Author

This simple class can get the names of each primary PHP data type.

It contains constants with the string values of all PHP variable types.

Applications can use it to get the names of the types to use this class together with the PHP functions SetType and GetType.

Innovation Award
PHP Programming Innovation award nominee
August 2022
Number 9
PHP is a weakly typed language. This fact means that it allows setting the type of variable values when executing the PHP code.

Although this makes the PHP language very flexible and tolerant of the developer's mistakes, sometimes it can be hard to debug subtle bugs caused by the developer's errors.

In practice, that can mean that developers may take more time to fix subtle bugs that probably would not exist if PHP was a strongly typed language.

This package provides a solution that can help to avoid those bugs. It gives the name strings of the PHP variable types.

So, if a developer wants to use the PHP GetType and SetType functions to get or set the variable type, the developer can use this class.

So, if the developer makes a mistake in the name of a constant provided by the class, PHP will trigger an error that can make it easier to find bugs caused by typing the name of a PHP type.

Manuel Lemos
Picture of Pierre-Henry Soria
  Performance   Level  
Name: Pierre-Henry Soria <contact>
Classes: 49 packages by
Country: United Kingdom
Age: 31
All time rank: 37316 in United Kingdom
Week rank: 1 Up
Innovation award
Innovation award
Nominee: 18x

Winner: 3x

Documentation

PHP type names ??

Get all valid PHP type names with constants.

? Overview

Simple library containing the list of constants for the available PHP data types. Use those constant types in your project when you need to mention a data type, use those constants instead of hardcoding them.

?? Requirements

?? Installation

Install it easily with Composer

composer require ph-7/datatype

? Example

require_once __DIR__ . '/vendor/autoload.php';

use PH7\Datatype\Type;

$id = settype($_GET['id'], Type::STRING);

$name = settype($inputName, Type::STRING);

? Who cooked it?

Pierre-Henry Soria

[![@phenrysay][twitter-image]](https://twitter.com/phenrysay) [![pH-7][github-image]](https://github.com/pH-7)

Pierre-Henry Soria, a highly passionate, zen &amp; pragmatic software engineer ?

?? License

PHP type names is generously distributed under the MIT.

<!-- GitHub's Markdown reference links --> [twitter-image]: https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white [github-image]: https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white

<!-- Generated by https://github.com/pH-7/cool-readme-generator -->


  Files folder image Files (7)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (7)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (7)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test.yml Data Auxiliary data

  Files folder image Files (7)  /  src  
File Role Description
  Plain text file Type.php Class Class source

  Files folder image Files (7)  /  tests  
File Role Description
  Plain text file TypeTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:68
This week:0
All time:10,325
This week:660Up