Lang

From struts4php

Jump to: navigation, search

PHP provides no support for basic datatype objects like a String. In some cases, it may be useful to have such types, e. g. for make the parameter of a method type safe. These package adds the four base types

  • String
  • Integer
  • Float
  • Boolean

to your application.

String

The String class is a wrapper class for the php datatype string. The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.

String conversions are implemented through the method toString, defined by Object and inherited by all classes in the framework.

Example:

include_once "lang/string.php";
 
$string = new String("foo");
echo $string->length(); // prints out the strings length, 3 in this case

Integer

The Integer class is a wrapper class for the php datatype integer. The class provides methods for string to Integer conversion and backwards.

Example:

include_once "lang/integer.php";
 
$integer = Integer::valueOf(new String("1")); // parses the String and creates a new Integer object from the String value
Personal tools