PHP Classes

File: String.php

Recommend this page to a friend!
  Classes of Martin Alterisio   Type Hint Class   String.php   Download  
File: String.php
Role: Class source
Content type: text/plain
Description: String TypeHint
Class: Type Hint Class
Implement type hinting support for base PHP types
Author: By
Last change: Accessible without user login
Date: 16 years ago
Size: 841 bytes
 

Contents

Class file image Download
<?php
/**
 * @package typehintclass
 */

/**
 * Type hint class for all values that can be used as strings.
 */
final class String implements TypeHint {
   
/**
     * Type hint class, cannot be instantiated nor extended.
     */
   
private function __construct() { }
   
   
/**
     * Indicates if this class represents a type hint for provided value.
     * @param mixed $value The value.
     * @return bool True if this class represents a type hint for that value.
     */
   
public static function isTypeHintFor($value) {
        if (
is_string($value)) {
            return
true;
        } else if (
is_int($value) || is_float($value)) {
            return
true;
        } else if (
is_object($value)) {
            return
method_exists($value, '__toString');
        }
        return
false;
    }
}
?>