gettype

  • Variables in Ruby don’t have a type. Instead they are an instance of an object. We can interrogate the class of an object instance using Object#class.

    PHP

    print gettype(true);         // => boolean
    print gettype(1);            // => integer
    print gettype(1.2);          // => double
    print gettype('hello');      // => string
    print gettype(new stdClass); // => object
    print gettype(null);         // => NULL

    Ruby

    true.class       # => TrueClass
    1.class          # => Fixnum
    1.2.class        # => Float
    "hello".class    # String
    Object.new.class # Object
    nil.class        # NilClass

    see also

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.