005PHP_ Types - Manual

download 005PHP_ Types - Manual

of 3

Transcript of 005PHP_ Types - Manual

  • 7/28/2019 005PHP_ Types - Manual

    1/3

    [edit] Last updated: Fri, 20 Apr 2012

    Types

    Table of Contents

    Introduction

    Booleans

    Integers

    Floating point numbers

    Strings

    Arrays

    Objects

    Resources

    NULL

    Callbacks

    Pseudo-types and variables used in this documentation

    Type Juggling

    User Contributed Notes Types

    Jeffrey 26-Oct-2008 10:31

    The Object (compound) Type

    Like every programming language, PHP offers the usual basic primitive types which can hold only one piece of data at a time (scalar). I am

    particularly fond of the "object" type (compound) because that allows me to group many basic PHP types together, and I can name it anything

    I want.

  • 7/28/2019 005PHP_ Types - Manual

    2/3

    1 of 3 26/04/2012 11:04

    $hasDriversLicense; // a PHP Boolean

    }

    ?>

    Here, I have grouped several basic PHP types together, (3) Strings, (1) Integer, and (1) Boolean... then I named that group "Person". Since

    I used the proper syntax to do so, this code is pure PHP, which means that if you run this code, you would have an extra PHP "type"

    available to you in your scripts, like so:

    You can make your own object types and have PHP execute it as if it were part of the PHP language itself. See more on classes and objects

    in this manual at: http://www.php.net/manual/en/language.oop5.php

    arjini at gmail dot com 06-Dec-2005 12:32

    Note that you can chain type castng:

    var_dump((string)(int)false); //string(1) "0"

    shahnaz khan 18-Mar-2005 04:40

    if we use gettype() before initializinf any variable it give NULL

    for eg.

    it will show

    NULL

    Trizor of www.freedom-uplink.org 29-Jun-2004 06:14

    PHP: Types - Manual http://www.php.net/manual/en/language.types.php

    2 of 3 26/04/2012 11:04

  • 7/28/2019 005PHP_ Types - Manual

    3/3

    The differance of float and double dates back to a FORTRAN standard. In FORTRAN Variables aren't as loosly written as in PHP and you had to

    define variable types(OH NOES!). FLOAT or REAL*4 (For all you VAX people out there) defined the variable as a standard precision floating

    point, with 4 bytes of memory allocated to it. DOUBLE PRECISION or REAL*8 (Again for the VAX) was identical to FLOAT or REAL*4, but with an

    8 byte allocation of memory instead of a 4 byte allocation.

    In fact most modern variable types date back to FORTRAN, except a string was called a CHARACHTER*N and you had to specify the length, or

    CHARACHTER*(*) for a variable length string. Boolean was LOGICAL, and there weren't yet objects, and there was support for complex

    numbers(a+bi).

    Of course, most people reading this are web programmers and could care less about the mathematical background of programming.

    NOTE: Object support was added to FORTRAN in the FORTRAN90 spec, and expanded with the FORTRAN94 spec, but by then C was the powerful force

    on the block, and most people who still use FORTRAN use the FORTRAN77.

    Copyright 2 001-2012 The PHP GroupAll rights reserved.

    PHP: Types - Manual http://www.php.net/manual/en/language.types.php

    3 f 3 26/04/2012 11 04