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()).

Answer from madsen on Stack Overflow
Discussions

[RFC] typeof() in PHP 7.1
Sounds like a good approach to make PHP actually has a typeof() in par with other languages. I personally think it should return the bare minimum details and not detailed ones as "closed resource" and such. Basically to have a (short) known list of possible return values. More on reddit.com
๐ŸŒ r/PHP
45
52
June 4, 2016
Alias for is_object($var) ? get_class($var) : gettype($var)

Here you go:

function get_real_type($var)
{
    return is_object($var) ? get_class($var) : gettype($var);
}

Do we really need to add another function to ext/standard for this?

More on reddit.com
๐ŸŒ r/PHP
8
1
November 12, 2015
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-gettype-function
PHP gettype() Function - GeeksforGeeks
September 13, 2024 - The PHP gettype() function returns the type of a variable as a string. It identifies the variable's data type, such as string, integer, array, boolean, etc., allowing developers to check and handle different data types dynamically.
๐ŸŒ
Reintech
reintech.io โ€บ blog โ€บ a-practical-guide-to-php-gettype-function
A Practical Guide to PHP's `gettype()` Function
April 14, 2023 - The gettype() function returns a string representation of a variable's type. Its simple signature makes it accessible for quick type inspection: ... This function returns one of eight possible string values corresponding to PHP's core data types.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ php โ€บ php_gettype_function.htm
PHP Variable Handling gettype() Function
The PHP Variable Handling gettype() function is used to PHP's gettype() function is useful to identify the type of a variable. It returns the type as a string, such "integer" or "string".
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ php tutorial โ€บ php gettype()
PHP gettype() | Working of gettype() Function with Examples
April 5, 2023 - PHP comes out with the function of gettype, which is used to get the type of a given variable. Whatever the variables we have to get the type of that, we use the function gettype() in PHP.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
w3resource
w3resource.com โ€บ php โ€บ function-reference โ€บ gettype.php
PHP gettype() function - w3resource
August 19, 2022 - (PHP 4 and above) Syntax: gettype(var_name) Parameter: *Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types. Return value ยท Possible values of the returned string: boolean ยท integer ยท double ยท string ยท array ยท object ยท resource ยท
Find elsewhere
๐ŸŒ
W3Schools
w3schools.in โ€บ php โ€บ gettype-function
gettype() Function in PHP - W3schools
The gettype() function is an inbuilt library function in PHP used to obtain the data type of an existing variable. It helps the programmer to find the type of data associated with a particular variable that is needed in the program itself.
๐ŸŒ
TechBriefers
techbriefers.com โ€บ how-to-check-data-type-in-php-gettype-function-php
How to check Datatype in PHP - PHP gettype() | TechBriefers
August 8, 2023 - The PHP gettype() function is a PHP function that is used to check the type of variables. This PHP gettype() function returns the data type of the variable value passed as an argument and returns a string which is a clear data type of the passed ...
๐ŸŒ
Plus2Net
plus2net.com โ€บ php_tutorial โ€บ gettype.php
gettype() to get type of variable in PHP
<?Php $my_var=true; echo gettype($my_var); // boolean echo "<br>"; echo var_dump($my_var); // bool(true) $my_var=5; echo gettype($my_var); // integer echo "<br>"; echo var_dump($my_var); // int(5) $my_var=5.6; echo gettype($my_var); // double echo "<br>"; echo var_dump($my_var); // flot(5.6) $my_var='plus2net.com'; echo gettype($my_var); // string echo "<br>"; echo var_dump($my_var); // string(12) "plus2net.com" $my_var=Null; echo gettype($my_var); // NULL echo "<br>"; echo var_dump($my_var); // NULL $my_var=array('Mango','Banana','Apple'); echo gettype($my_var); // array echo "<br>"; echo var_dump($my_var); //array(3) { [0]=> string(5)"Mango" [1]=> string(6) "Banana" [2]=> string(5) "Apple" } ?> โ†Declaring variables isset()โ†’ empty()โ†’ var_dump()โ†’
๐ŸŒ
BCCNsoft
doc.bccnsoft.com โ€บ docs โ€บ php-docs-7-en โ€บ function.gettype.html
Get the type of a variable
<?php $data = array(1, 1., NULL, new stdClass, 'foo'); foreach ($data as $value) { echo gettype($value), "\n"; } ?>
๐ŸŒ
Altorouter
altorouter.com โ€บ home โ€บ master phpโ€™s gettype function: a detailed guide
Understanding PHP Get Type: Mastering the Function
January 22, 2024 - In PHP, a language that does not require explicit variable type declaration, the `gettype()` function emerges as a crucial tool. It allows programmers to ascertain the data type of a variable, which is essential in various operations and debugging ...
๐ŸŒ
3D Bay
clouddevs.com โ€บ home โ€บ php guides โ€บ deciphering phpโ€™s gettype() function: a detailed guide
Deciphering PHP's gettype() Function: A Detailed Guide
December 13, 2023 - In this example, we set $status to null and then use gettype() to determine that it is of type NULL. PHP is a dynamically typed language, which means that variable types can change during runtime.
๐ŸŒ
OnlinePHP
onlinephp.io โ€บ gettype โ€บ manual
gettype - OnlinePHP.io Example
gettype( mixed$value ): string ยท Returns the type of the PHP variable value. For type checking, use is_* functions. value ยท The variable being type checked. Possible values for the returned string are: "boolean" "integer" "double" (for historical ...
๐ŸŒ
AlphaCodingSkills
alphacodingskills.com โ€บ php โ€บ notes โ€บ php-variable-handling-gettype.php
PHP gettype() Function - AlphaCodingSkills
The PHP gettype() function returns the type of the PHP variable. As of PHP 7.2.0, closed resources is reported as resource (closed). Previously the ...
๐ŸŒ
IncludeHelp
includehelp.com โ€บ php โ€บ gettype-function-with-example.aspx
PHP gettype() Function (With Examples)
In PHP, we have a library function gettype() to identify the type of data. The function is primarily used to sanity check the type of data being input in a variable.