Skip to content

PHP Component - Data Type

By using this component, you are able to use type hints also for basic data types.
This component includes class definitions for php basic data types like:

  • Boolean
  • Floating point
  • Integer
  • String
  • Numeric

Features

  • Enables type hints for basic php types
  • Types shipped with useful methods
  • Are comparable with native php types by using "=="
  • Provides generic type casting by implemented "toString()" methods (and so on)

Usage

Example


/**
 * Class with type hint for string
 *
 * @author stev leibelt 
 * @since 2013-08-04
 */
class MyClass
{
    /**
     * @var array
     * @author stev leibelt 
     * @since 2013-08-04
     */
    private $strings = array();

    /**
     * Super cool method with type hint for string
     *
     * @author stev leibelt 
     * @since 2013-08-04
     */
    public function addString(\Net\Bazzline\Component\DataType\String $string)
    {
        $this->strings[] = $string;

        return $this;
    }
}

$myString = new \Net\Bazzline\Component\DataType\String('super cool test string');

$myClass = new MyClass();
$myClass->addString($myString);

Hints

  • Extend provided types with classes in own namespace.
  • If you add a super cool method to your type, push it and be a part of the development team

Install

Via Git


cd path/to/my/git/respositories
mkdir -p stevleibelt/php_component_data_type
cd stevleibelt/php_component_data_type

git clone git://github.com/stevleibelt/php_component_data_type.git .

Via Composer


require: "net_bazzline/component_data_type": "dev-master"

Why?

I started developing this component because of the many casts i have to do while dealing with php's basic data types. As general, i searched the web for existing and easy to use components but could not find them. If you find one, please tell me. Last but not least SplTypes are still experimental.

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options