class Person { public $name = 'John'; protected $age = 25; private $gender = 'Male'; } $ref = new ReflectionProperty('Person', 'gender'); echo $ref->getDeclaringClass()->name;
class Product { private $name; private $price; public function __construct($n, $p) { $this->name = $n; $this->price = $p; } public function getName() { return $this->name; } public function getPrice() { return $this->price; } } $ref = new ReflectionProperty('Product', 'name'); echo $ref->getDeclaringClass()->name;This code creates a class called Product with two private properties - name and price. The constructor and two getter methods are also defined. Again, the getDeclaringClass() method is used to get the class that declared the name property. The output of this code would be "Product". This example may come from a package or library related to e-commerce or product management.