Get Functions

 <?php

//There are many Get Functions in PHP as shown below:
//get_class, get_parent_class, get_class_methods, get_class_vars, get_object_vars, get_called_class,
//get_declared_classes, get_declared_interfaces, get_declared_traits, class_alias

class ParentClass
{
    function name()
    {
        echo "Class Name : " . get_class($this) . "<br>";   //Print the particualr Class Name
        //Print the particular Parent Class Name as shown below:
        echo "Parent Class Name : " . get_parent_class($this) . "<br>";
    }
}
class ChildClass extends ParentClass
{
    function __construct()
    {}
    function myfunction()
    {}
    function myfunction2()
    {}
}
$obj = new ChildClass();
$obj->name();
echo "Class Name is : " . get_class($obj) . "<br>";
echo "Parent Class Name : " . get_parent_class("ChildClass") . "<br>";
$class_methods = get_class_methods("ChildClass");   //Getting all the Methods present in the Class
echo "<pre>";
print_r($class_methods);    //Print all the Methods Names
echo "</pre>";

foreach($class_methods as $methods)
{
    echo $methods . "<br>"; //Print all the Methods using foreach() loop
}
echo "<br>";

class MyClass
{
    public $var1;
    public $var2 = "Hello";
    public $var3 = 100;
    private $var4;

    function __construct()
    {
        $this->var1 = "Wow";
        echo "<pre>";
        print_r(get_class_vars(__CLASS__));
        echo "</pre>";

        echo "<pre>";
        echo "All the Class's private and public variables:";
        print_r(get_object_vars($this));
        echo "</pre>";
    }

}
$myObj = new MyClass();
$class_vars = get_class_vars(get_class($myObj));
echo "<pre>";
print_r($class_vars);
echo "</pre>";

$class_vars2 = get_object_vars($myObj);
echo "<pre>";
print_r($class_vars2);
echo "</pre>";
echo "<br>";

//  get_called_class() function shows that for which class this function is Called.
class Abc
{
    static public function test()
    {
        var_dump(get_called_class());
    }
}
class Xyz extends Abc
{}
Abc::test();
Xyz::test();

//get_declared_classes() function returns Array of total number of classes present in current page
echo "<pre>";
print_r(get_declared_classes());
echo "</pre>";

interface inf
{}
interface play
{}
interface Round
{}

//get_declared_interfaces() function returns Array of total number of interfaces present in current page
echo "<pre>";
print_r(get_declared_interfaces());
echo "</pre>";

trait Flow
{}
trait Manage
{}
trait basic
{}

// get_declared_traits() function returns Array of Total number of traits present in current page
echo "<pre>";
print_r(get_declared_traits());
echo "</pre>";

//We can give another Name (Alias name) to Class as shown below using class_alias() function
class Myclass2
{
    public $test;
}
class_alias("Myclass","Mc");

$obj = new Myclass2();
$obj2 = new Mc();

echo $obj->test = "Hello" . "<br>";
echo $obj2->test = "World";

//  OUTPUT:
//Class Name : ChildClass
// Parent Class Name : ParentClass
// Class Name is : ChildClass
// Parent Class Name : ParentClass
// Array
// (
//     [0] => __construct
//     [1] => myfunction
//     [2] => myfunction2
//     [3] => name
// )
// __construct
// myfunction
// myfunction2
// name

// Array
// (
//     [var1] =>
//     [var2] => Hello
//     [var3] => 100
//     [var4] =>
// )
// All the Class's private and public variables:Array
// (
//     [var1] => Wow
//     [var2] => Hello
//     [var3] => 100
//     [var4] =>
// )
// Array
// (
//     [var1] =>
//     [var2] => Hello
//     [var3] => 100
// )
// Array
// (
//     [var1] => Wow
//     [var2] => Hello
//     [var3] => 100
// )

// string(3) "Abc" string(3) "Xyz"
// Array
// (
//     [0] => InternalIterator
//     [1] => Exception
//     [2] => ErrorException
//     [3] => Error
//     [4] => CompileError
//     [5] => ParseError
//     [6] => TypeError
//     [7] => ArgumentCountError
//     [8] => ValueError
//     [9] => ArithmeticError
//     [10] => DivisionByZeroError
//     [11] => UnhandledMatchError
//     [12] => Closure
//     [13] => Generator
//     [14] => ClosedGeneratorException
//     [15] => WeakReference
//     [16] => WeakMap
//     [17] => Attribute
//     [18] => ReturnTypeWillChange
//     [19] => AllowDynamicProperties
//     [20] => SensitiveParameter
//     [21] => SensitiveParameterValue
//     [22] => Fiber
//     [23] => FiberError
//     [24] => stdClass
//     [25] => DateTime
//     [26] => DateTimeImmutable
//     [27] => DateTimeZone
//     [28] => DateInterval
//     [29] => DatePeriod
//     [30] => HashContext
//     [31] => JsonException
//     [32] => LogicException
//     [33] => BadFunctionCallException
//     [34] => BadMethodCallException
//     [35] => DomainException
//     [36] => InvalidArgumentException
//     [37] => LengthException
//     [38] => OutOfRangeException
//     [39] => RuntimeException
//     [40] => OutOfBoundsException
//     [41] => OverflowException
//     [42] => RangeException
//     [43] => UnderflowException
//     [44] => UnexpectedValueException
//     [45] => RecursiveIteratorIterator
//     [46] => IteratorIterator
//     [47] => FilterIterator
//     [48] => RecursiveFilterIterator
//     [49] => CallbackFilterIterator
//     [50] => RecursiveCallbackFilterIterator
//     [51] => ParentIterator
//     [52] => LimitIterator
//     [53] => CachingIterator
//     [54] => RecursiveCachingIterator
//     [55] => NoRewindIterator
//     [56] => AppendIterator
//     [57] => InfiniteIterator
//     [58] => RegexIterator
//     [59] => RecursiveRegexIterator
//     [60] => EmptyIterator
//     [61] => RecursiveTreeIterator
//     [62] => ArrayObject
//     [63] => ArrayIterator
//     [64] => RecursiveArrayIterator
//     [65] => SplFileInfo
//     [66] => DirectoryIterator
//     [67] => FilesystemIterator
//     [68] => RecursiveDirectoryIterator
//     [69] => GlobIterator
//     [70] => SplFileObject
//     [71] => SplTempFileObject
//     [72] => SplDoublyLinkedList
//     [73] => SplQueue
//     [74] => SplStack
//     [75] => SplHeap
//     [76] => SplMinHeap
//     [77] => SplMaxHeap
//     [78] => SplPriorityQueue
//     [79] => SplFixedArray
//     [80] => SplObjectStorage
//     [81] => MultipleIterator
//     [82] => Random\RandomError
//     [83] => Random\BrokenRandomEngineError
//     [84] => Random\RandomException
//     [85] => Random\Engine\Mt19937
//     [86] => Random\Engine\PcgOneseq128XslRr64
//     [87] => Random\Engine\Xoshiro256StarStar
//     [88] => Random\Engine\Secure
//     [89] => Random\Randomizer
//     [90] => ReflectionException
//     [91] => Reflection
//     [92] => ReflectionFunctionAbstract
//     [93] => ReflectionFunction
//     [94] => ReflectionGenerator
//     [95] => ReflectionParameter
//     [96] => ReflectionType
//     [97] => ReflectionNamedType
//     [98] => ReflectionUnionType
//     [99] => ReflectionIntersectionType
//     [100] => ReflectionMethod
//     [101] => ReflectionClass
//     [102] => ReflectionObject
//     [103] => ReflectionProperty
//     [104] => ReflectionClassConstant
//     [105] => ReflectionExtension
//     [106] => ReflectionZendExtension
//     [107] => ReflectionReference
//     [108] => ReflectionAttribute
//     [109] => ReflectionEnum
//     [110] => ReflectionEnumUnitCase
//     [111] => ReflectionEnumBackedCase
//     [112] => ReflectionFiber
//     [113] => SessionHandler
//     [114] => __PHP_Incomplete_Class
//     [115] => AssertionError
//     [116] => php_user_filter
//     [117] => Directory
//     [118] => PhpToken
//     [119] => InflateContext
//     [120] => DeflateContext
//     [121] => LibXMLError
//     [122] => DOMException
//     [123] => DOMImplementation
//     [124] => DOMNode
//     [125] => DOMNameSpaceNode
//     [126] => DOMDocumentFragment
//     [127] => DOMDocument
//     [128] => DOMNodeList
//     [129] => DOMNamedNodeMap
//     [130] => DOMCharacterData
//     [131] => DOMAttr
//     [132] => DOMElement
//     [133] => DOMText
//     [134] => DOMComment
//     [135] => DOMCdataSection
//     [136] => DOMDocumentType
//     [137] => DOMNotation
//     [138] => DOMEntity
//     [139] => DOMEntityReference
//     [140] => DOMProcessingInstruction
//     [141] => DOMXPath
//     [142] => PDOException
//     [143] => PDO
//     [144] => PDOStatement
//     [145] => PDORow
//     [146] => SimpleXMLElement
//     [147] => SimpleXMLIterator
//     [148] => XMLParser
//     [149] => XMLReader
//     [150] => XMLWriter
//     [151] => OpenSSLCertificate
//     [152] => OpenSSLCertificateSigningRequest
//     [153] => OpenSSLAsymmetricKey
//     [154] => CurlHandle
//     [155] => CurlMultiHandle
//     [156] => CurlShareHandle
//     [157] => CURLFile
//     [158] => CURLStringFile
//     [159] => finfo
//     [160] => mysqli_sql_exception
//     [161] => mysqli_driver
//     [162] => mysqli
//     [163] => mysqli_warning
//     [164] => mysqli_result
//     [165] => mysqli_stmt
//     [166] => PharException
//     [167] => Phar
//     [168] => PharData
//     [169] => PharFileInfo
//     [170] => FTP\Connection
//     [171] => ParentClass
//     [172] => ChildClass
//     [173] => MyClass
//     [174] => Abc
//     [175] => Xyz
//     [176] => Myclass2
// )
// Array
// (
//     [0] => Traversable
//     [1] => IteratorAggregate
//     [2] => Iterator
//     [3] => Serializable
//     [4] => ArrayAccess
//     [5] => Countable
//     [6] => Stringable
//     [7] => Throwable
//     [8] => UnitEnum
//     [9] => BackedEnum
//     [10] => DateTimeInterface
//     [11] => JsonSerializable
//     [12] => RecursiveIterator
//     [13] => OuterIterator
//     [14] => SeekableIterator
//     [15] => SplObserver
//     [16] => SplSubject
//     [17] => Random\Engine
//     [18] => Random\CryptoSafeEngine
//     [19] => Reflector
//     [20] => SessionHandlerInterface
//     [21] => SessionIdInterface
//     [22] => SessionUpdateTimestampHandlerInterface
//     [23] => DOMParentNode
//     [24] => DOMChildNode
//     [25] => inf
//     [26] => play
//     [27] => Round
// )
// Array
// (
//     [0] => Flow
//     [1] => Manage
//     [2] => basic
// )
// Array
// (
//     [var1] =>
//     [var2] => Hello
//     [var3] => 100
//     [var4] =>
// )
// All the Class's private and public variables:Array
// (
//     [var1] => Wow
//     [var2] => Hello
//     [var3] => 100
//     [var4] =>
// )
// Hello
// World

?>

Comments

Popular posts from this blog

GROUP BY Clause and HAVING Clause in PHP

Method Overriding in Traits in PHP

Mysqli database Connection and Display Table Data from Database