Content · Programming · PHP

PHP ReflectionClass::isInternal() Method: Usage and Examples

PHP ReflectionClass::isInternal() Method: Usage and Examples: Reports whether the class is supplied by PHP or an installed extension rather than user source code.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 Know-Stuff

ReflectionClass inspects the definition of a class, rather than running its constructor or calling its methods.

What Is ReflectionClass::isInternal in PHP?


Reports whether the class is supplied by PHP or an installed extension rather than user source code.

ReflectionClass::isInternal()

This operation does not accept method arguments.

Example 1: Understanding the Basic Behavior


<?php

$reflectionClass = new ReflectionClass(DateTimeImmutable::class);
var_dump($reflectionClass->isInternal());

Output:

bool(true)

Explanation: Reports whether the class is supplied by PHP or an installed extension rather than user source code.

Example 2: Testing Another Case


<?php

interface Exportable { public function export(): string; }
trait HasId { public function getId(): int { return 12; } }
class Invoice implements Exportable { use HasId; public string $name = 'Invoice'; public const STATE = 'open'; public function export(): string { return 'invoice'; } }
$reflectionClass = new ReflectionClass(Invoice::class);
$result = $reflectionClass->isInternal();
var_dump($result);

Output:

bool(false)

Explanation: PHP or extension-provided types report true; ordinary application-defined classes report false.

Practical Example: Applying the Operation


<?php

abstract class BaseJob { protected string $name = 'job'; abstract public function run(): void; }
class CompletedJob extends BaseJob { public function run(): void {} }
$reflectionClass = new ReflectionClass(CompletedJob::class);
$result = $reflectionClass->isInternal();
var_dump($result);

Output:

bool(false)

Explanation: The returned metadata may be false, null, an array, or a Reflection object depending on the requested property.

Important Behavior and Edge Cases


  • PHP or extension-provided types report true; ordinary application-defined classes report false.
  • The returned metadata may be false, null, an array, or a Reflection object depending on the requested property.

Comparison With Related Approaches


ApproachWhen to Use It
ReflectionClass::isInternalReports whether the class is supplied by PHP or an installed extension rather than user source code.
ReflectionClass::getExtensionName()isInternal() reports whether PHP or an extension supplies the class; getExtensionName() identifies the extension if present.

Common Beginner Mistakes


MistakeCorrect Approach
Confusing a class-declaration check by ReflectionClass::isInternal() with an invocation of the class itself.PHP or extension-provided types report true; ordinary application-defined classes report false.
Choosing ReflectionClass::getExtensionName() without checking whether it provides the same result.isInternal() reports whether PHP or an extension supplies the class; getExtensionName() identifies the extension if present.

Key Takeaways


  • Reports whether the class is supplied by PHP or an installed extension rather than user source code.
  • PHP or extension-provided types report true; ordinary application-defined classes report false.
  • The returned metadata may be false, null, an array, or a Reflection object depending on the requested property.

The examples demonstrate where ReflectionClass::isInternal fits within reflection and metadata. Verify the relevant preconditions whenever you adapt the code to real data.

Share this resourceSend this page to someone who may find it useful.