class MyClass { public function &myMethod() { $var = "Hello"; return $var; } } $obj = new MyClass(); $method = new ReflectionMethod($obj, "myMethod"); if ($method->returnsReference()) { echo "myMethod returns a reference"; } else { echo "myMethod does not return a reference"; }
function &myFunction() { $var = "World"; return $var; } $function = new ReflectionFunction("myFunction"); if ($function->returnsReference()) { echo "myFunction returns a reference"; } else { echo "myFunction does not return a reference"; }In this example, we define a function `myFunction` that returns a reference `&` to a variable `$var`. We then obtain a `ReflectionFunction` object for the function and check its `returnsReference` property using an `if` statement. Based on these examples, it appears that `ReflectionMethod` and `ReflectionFunction` are part of PHP's built-in reflection library.