PHP SPL Types

The PHP programming language first came into existence to serve as a scripting language that allows programmers to quickly develop interactive Web pages that can change the state of the Web browser or make queries to the underlying server database. However, PHP did not contain man internal object types, such as data structures or strongly typed values. The Standard PHP Library (SPL) attempts to correct this by adding strongly-types variables and data structures to PHP.

  1. Strongly-Typed and Weakly-Typed Languages

    • Typed languages are those languages that require programmers to define variable data types when declaring variables in code. Languages such as Java and C++ are strongly typed. In contrast, weakly-typed languages do not require programmers to define data type, and thus a variable can hold any type of value. Many interpreted scripting languages such as PHP and Python follow this paradigm.

    SPL Data Types

    • To offer strongly-typed variable use to PHP, the SPL contains a variety of built-in types. This becomes particularly useful when taking advantage of PHP5's object-oriented capabilities. The types included in SPL allow programmers to define how they interact with the interpreter and with other types, and include classes that represent basic data types such as Booleans (SplBool), integers (SplInt), and floating-point decimals (SplFloat).

    Data Structures and Exceptions

    • In object-oriented programming, special classes exist that allow programmers to interact with objects in productive ways. Data structures allow programmers to create objects that organize data in a particular way, so that efficient retrieval and sorting algorithms can work on the data. Exceptions represent classes that handle errors. Exceptions "catch" when the compiler throws a particular error, and allows the programmer to handle that error by taking an alternative course of action or correcting the code.

    SPL Classes

    • With the addition of the SPL, programmers now have access to numerous classes that wrap data structures such as arrays, or behave as new data structures such as trees or lists. Furthermore, the SPL defines numerous class that can be modified to traverse these structures in the way the programmer sees fit. Finally, the SPL defines a series of exception classes that programmers can use to define when particular errors take place in these new classes or objects.

Related Searches:

References

Comments

Related Ads

Featured