PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] get type in php returns "object" and not the object type

 January 13, 2022     php     No comments   

Issue

im trying to get the type of the object that i receive in the constructor using gettype($this->object) . but im only getting "object" my constructor: p

public function __construct($object=null)
    {
        $this->object=$object;

    }

the object that i send to class:

$campaign = new Campaign();

$type = new Nodes\CampaignDatabaseNode($campaign);
$type->checkType();

the checkType(); only echo the type of the object


Solution

Just to explain why gettype() doesn't work as expected since others have already provided the correct answer. gettype() returns the type of variable — i.e. boolean, integer, double, string, array, object, resource, NULL or unknown type (cf. the gettype() manual link above).

In your case the variable $campaign is an object (as returned by gettype()), and that object is an instance of the class Campaign (as returned by get_class()).



Answered By - madsen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing