1

for instance

I've a class called Ent, and have an object $ent

how can I get the class Ent out of $ent?

$ent =    new Ent()
1
  • 2
    what do u mean by OUT OF ?? Commented Jul 16, 2014 at 16:30

4 Answers 4

1
get_class(new Ent())

this will even work in earlier versions of PHP

Sign up to request clarification or add additional context in comments.

Comments

0

You can use get_class($ent)

get_class - Returns the name of the class of an object

Reference php docs

Comments

0

You could get get_class().

Watch out though, if your calling it on a variable that might not be an object it will throw a warning.

if(is_object($ent))
{
    $class = get_class($ent);
}

Ref: http://php.net/manual/en/function.get-class.php

Comments

0
$ent = new Ent();    
$my_class = get_class($ent);
$new_ent = new $my_class;

RTM: Here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.