object-reflector Documentation

Allows reflection of object attributes, including inherited and non-public ones

6,271 stars PHP PHP 1 file ยท ~6,459 tokens
RAW Doc

File: README.md



sebastian/object-reflector

Allows reflection of object properties, including inherited and private as well as protected ones.

Installation

You can add this library as a local, per-project dependency to your project using Composer:

text
composer require sebastian/object-reflector

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

text
composer require --dev sebastian/object-reflector

File: ChangeLog.md

Change Log

All notable changes to sebastianbergmann/object-reflector are documented in this file using the Keep a CHANGELOG principles.

[6.1.0] - 2026-08-13

Changed

  • Improved performance of ObjectReflector::getProperties()

Fixed

  • A property whose name contains a null byte is no longer reflected under a wrong name
  • The name of a private property of an object of an anonymous class is no longer lost

[6.0.0] - 2026-02-06

Removed

  • This component is no longer supported on PHP 8.3

[5.0.0] - 2025-02-07

Removed

  • This component is no longer supported on PHP 8.2

[4.0.1] - 2024-07-03

Changed

  • This project now uses PHPStan instead of Psalm for static analysis

[4.0.0] - 2024-02-02

Removed

  • This component is no longer supported on PHP 8.1

[3.0.0] - 2023-02-03

Changed

  • ObjectReflector::getAttributes() has been renamed to ObjectReflector::getProperties()

Removed

  • This component is no longer supported on PHP 7.3, PHP 7.4 and PHP 8.0

[2.0.4] - 2020-10-26

Fixed

  • SebastianBergmann\ObjectReflector\Exception now correctly extends \Throwable

[2.0.3] - 2020-09-28

Changed

  • Changed PHP version constraint in composer.json from ^7.3 || ^8.0 to >=7.3

[2.0.2] - 2020-06-26

Added

  • This component is now supported on PHP 8

[2.0.1] - 2020-06-15

Changed

  • Tests etc. are now ignored for archive exports

[2.0.0] - 2020-02-07

Removed

  • This component is no longer supported on PHP 7.0, PHP 7.1, and PHP 7.2

[1.1.1] - 2017-03-29

  • Fixed #1: Attributes with non-string names are not handled correctly

[1.1.0] - 2017-03-16

Changed

  • Changed implementation of ObjectReflector::getattributes() to use (array) cast instead of ReflectionObject

1.0.0 - 2017-03-12

  • Initial release

File: composer.json

{
"name": "sebastian/object-reflector",
"description": "Allows reflection of object attributes, including inherited and non-public ones",
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
"security": "https://github.com/sebastianbergmann/object-reflector/security/policy"
},
"prefer-stable": true,
"config": {
"platform": {
"php": "8.4.1"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=8.4"
},
"require-dev": {
"phpunit/phpunit": "^13.4.3"
},
"autoload": {
"classmap": [
"src/"
]
},
"autoload-dev": {
"classmap": [
"tests/_fixture/"
]
},
"extra": {
"branch-alias": {
"dev-main": "6.1-dev"
}
}
}


File: renovate.json

{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
"helpers:pinGitHubActionDigestsToSemver",
":configMigration"
],
"timezone": "Europe/Berlin",
"baseBranchPatterns": [
"main",
"/^\d+\.\d+$/"
],
"rebaseWhen": "conflicted",
"prHourlyLimit": 2,
"prConcurrentLimit": 10,
"dependencyDashboard": true,
"labels": ["type/dependencies"],
"platformAutomerge": true,
"osvVulnerabilityAlerts": true,
"dependencyDashboardOSVVulnerabilitySummary": "all",
"vulnerabilityAlerts": {
"enabled": true,
"labels": ["type/security", "type/dependencies"]
},
"packageRules": [
{
"description": "Group GitHub Actions updates per branch into one PR, automerge",
"matchManagers": ["github-actions"],
"groupName": "github-actions",
"automerge": true
},
{
"description": "Automerge minor and patch updates after they have settled",
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
},
{
"description": "Do not update the PHP platform requirement in composer.json",
"matchManagers": ["composer"],
"matchDepNames": ["php"],
"enabled": false
},
{
"description": "Do not suggest major updates for Composer dependencies",
"matchManagers": ["composer"],
"matchUpdateTypes": ["major"],
"enabled": false
},
{
"description": "Bump composer.json ranges when updating dependencies",
"matchManagers": ["composer"],
"rangeStrategy": "bump"
}
]
}


File: SECURITY.md

Security Policy

The library that is developed in this repository is a first-party dependency of PHPUnit.
PHPUnit's Security Policy applies to this library as well.

If you believe you have found a security vulnerability in this library, please report it to me through coordinated disclosure.

Use my PGP key for encrypted email, for example when your report includes proof-of-concept exploits against third-party systems.

Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.


File: tools/.phpstan/composer.json

{
"require-dev": {
"phpstan/phpstan": "^2.3.1",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan-strict-rules": "^2.1.0",
"ergebnis/phpstan-rules": "^2.14.2"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}


File: .github/CODE_OF_CONDUCT.md

Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

Examples of unacceptable behavior by participants include:

  • The use of sexualized language or imagery
  • Personal attacks
  • Trolling or insulting/derogatory comments
  • Public or private harassment
  • Publishing other's private information, such as physical or electronic
    addresses, without explicit permission
  • Other unethical or unprofessional conduct

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.

This Code of Conduct is adapted from the Contributor Covenant, version 1.3.0, available at https://contributor-covenant.org/version/1/3/0/


File: .github/CONTRIBUTING.md

Contributing to `sebastian/object-reflector`

Welcome!

We look forward to your contributions! Here are some examples how you can contribute:

We have a Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Any contributions you make will be under the BSD-3-Clause License

When you submit code changes, your submissions are understood to be under the same BSD-3-Clause License that covers the project. By contributing to this project, you agree that your contributions will be licensed under its BSD-3-Clause License.

Only submit a pull request with your own original code. Do NOT submit a pull request containing code which you have largely copied from
another project, unless you wrote the respective code yourself.

Open Source does not mean that copyright does not apply. Copyright infringements will not be tolerated and can lead to you being banned from this project and repository.

Do Not Submit AI-Generated Pull Requests

The same goes for (largely) AI-generated pull requests. These are not welcome as they will be based on copyrighted code from others
without accreditation and without taking the license of the original code into account, let alone getting permission
for the use of the code or for re-licensing.

Aside from that, the experience is that AI-generated pull requests will be incorrect 100% of the time and cost reviewers too much time.
Submitting a (largely) AI-generated pull request will lead to you being banned from this project and repository.

Write bug reports with detail, background, and sample code

This is an example of a bug report I wrote, and I think it's not too bad.

In your bug report, please provide the following:

  • A quick summary and/or background
  • Steps to reproduce
    • Be specific!
    • Give sample code if you can.
  • What you expected would happen
  • What actually happens
  • Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

Please do not report a bug for a version of this library that is no longer supported. Please do not report a bug if you are using a version of PHP that is not supported by the version of this library you are using.

The library that is developed in this repository was either extracted from PHPUnit or developed specifically as a dependency for PHPUnit. Support for this library follows the support for the version of PHPUnit that uses a specific version of this library.

Please post code and output as text (using proper markup). Do not post screenshots of code or output.

Workflow for Pull Requests

  1. Fork the repository.
  2. Create your branch from main if you plan to implement new functionality or change existing code significantly; create your branch from the oldest branch that is affected by the bug if you plan to fix a bug.
  3. Implement your change and add tests for it.
  4. Ensure the test suite passes.
  5. Ensure the code complies with our coding guidelines (see below).
  6. Send that pull request!

Please make sure you have set up your username and email address for use with Git. Strings such as silly nick name <root@localhost> look really stupid in the commit history of a project.

We encourage you to sign your Git commits with your GPG key.

Pull requests for bug fixes must be made for the oldest branch that is supported (see above). Pull requests for new features must be based on the main branch.

We are trying to keep backwards compatibility breaks to an absolute minimum. Please take this into account when proposing changes.

Due to time constraints, we are not always able to respond as quickly as we would like. Please do not take delays personal and feel free to remind us if you feel that we forgot to respond.

Development

This project uses PHPUnit for testing:

shell
./vendor/bin/phpunit

This project uses PHPStan for static analysis:

shell
./tools/phpstan

This project uses PHP-CS-Fixer to enforce coding guidelines:

shell
./tools/php-cs-fixer fix

The commands shown above require an autoloader script at vendor/autoload.php. This can be generated like so:

shell
./tools/composer dump-autoload

Please understand that we will not accept a pull request when its changes violate this project's coding guidelines or break the test suite.


File: .github/FUNDING.yml

github: sebastianbergmann
liberapay: sebastianbergmann
thanks_dev: u/gh/sebastianbergmann
tidelift: "packagist/sebastian/object-reflector"


File: .github/workflows/api-surface-check.yaml

https://github.com/marketplace/actions/api-surface-check-for-php

on:
pull_request:
paths-ignore:
- ".editorconfig"
- "LICENSE"
- ".md"
- "
.png"
- ".svg"
- "tests/
"

name: "API Surface Check"

permissions: {}

concurrency:
group: api-surface-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
signal:
name: Signal
runs-on: ubuntu-latest
steps:
- run: "true"


File: .github/workflows/api-surface-comment.yaml

https://github.com/marketplace/actions/api-surface-check-for-php

on:

zizmor: ignore[dangerous-triggers] workflow_run is required to comment on

PRs from forks; this workflow only runs a pinned action and does not check

out PR-controlled code.

workflow_run:
workflows: ["API Surface Check"]
types: [completed]

name: "API Surface Comment"

permissions:
contents: read

concurrency:
group: api-surface-comment-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

jobs:
check-api-surface:
name: Check API Surface
runs-on: ubuntu-latest
permissions:
pull-requests: write # required to post the API surface diff comment on the PR
steps:
- uses: composer/api-surface-check@bba9f1cb940df6e02271b1b6158679ac0b3f39d3 # 1.0.1


File: .github/workflows/ci.yaml

https://docs.github.com/en/actions

on:

  • pull_request
  • push

name: CI

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
COMPOSER_ROOT_VERSION: 6.1.x-dev
PHP_VERSION: 8.5

permissions:
contents: read

jobs:
coding-guidelines:
name: Coding Guidelines

text
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
  - name: Checkout
    uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      fetch-depth: 1
      ref: ${{ github.event.pull_request.head.sha || github.sha }}
      persist-credentials: false

  - name: Use local branch
    shell: bash
    env:
      EVENT_NAME: ${{ github.event_name }}
      HEAD_REF: ${{ github.head_ref }}
      REF_NAME: ${{ github.ref_name }}
    run: |
      if [ "$EVENT_NAME" = "pull_request" ]; then
        BRANCH="$HEAD_REF"
      else
        BRANCH="$REF_NAME"
      fi
      git branch -D "$BRANCH" 2>/dev/null || true
      git branch "$BRANCH" HEAD
      git checkout "$BRANCH"

  - name: Install PHP
    uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
    with:
      php-version: ${{ env.PHP_VERSION }}
      coverage: none
      tools: none

  - name: Run PHP-CS-Fixer
    run: ./tools/php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose

static-analysis:
name: Static Analysis

text
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
  - name: Checkout
    uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      fetch-depth: 1
      ref: ${{ github.event.pull_request.head.sha || github.sha }}
      persist-credentials: false

  - name: Use local branch
    shell: bash
    env:
      EVENT_NAME: ${{ github.event_name }}
      HEAD_REF: ${{ github.head_ref }}
      REF_NAME: ${{ github.ref_name }}
    run: |
      if [ "$EVENT_NAME" = "pull_request" ]; then
        BRANCH="$HEAD_REF"
      else
        BRANCH="$REF_NAME"
      fi
      git branch -D "$BRANCH" 2>/dev/null || true
      git branch "$BRANCH" HEAD
      git checkout "$BRANCH"

  - name: Install PHP
    uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
    with:
      php-version: ${{ env.PHP_VERSION }}
      coverage: none
      tools: none

  - name: Install dependencies with Composer
    run: ./tools/composer update --no-interaction --no-ansi --no-progress

  - name: Run PHPStan
    run: ./tools/phpstan analyse --no-progress --error-format=github

tests:
name: Tests

text
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
  fail-fast: false
  matrix:
    php-version:
      - 8.4
      - 8.5
      - 8.6
      - 8.7

steps:
  - name: Checkout
    uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      fetch-depth: 1
      ref: ${{ github.event.pull_request.head.sha || github.sha }}
      persist-credentials: false

  - name: Use local branch
    shell: bash
    env:
      EVENT_NAME: ${{ github.event_name }}
      HEAD_REF: ${{ github.head_ref }}
      REF_NAME: ${{ github.ref_name }}
    run: |
      if [ "$EVENT_NAME" = "pull_request" ]; then
        BRANCH="$HEAD_REF"
      else
        BRANCH="$REF_NAME"
      fi
      git branch -D "$BRANCH" 2>/dev/null || true
      git branch "$BRANCH" HEAD
      git checkout "$BRANCH"

  - name: Install PHP with extensions
    uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
    with:
      php-version: ${{ matrix.php-version }}
      ini-values: memory_limit=-1, zend.assertions=1, error_reporting=-1, display_errors=On, display_startup_errors=On
      coverage: none
      tools: none

  - name: Get Composer cache directory
    id: composer-cache
    shell: bash
    run: |
      echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

  - name: Cache Composer cache directory
    uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
    with:
      path: ${{ steps.composer-cache.outputs.dir }}
      key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
      restore-keys: ${{ runner.os }}-composer-

  - name: Install dependencies with Composer
    run: ./tools/composer update --no-ansi --no-interaction --no-progress

  - name: Run tests with PHPUnit
    run: vendor/bin/phpunit

code-coverage:
name: Code Coverage

text
needs:
  - tests

runs-on: ubuntu-latest
timeout-minutes: 5

steps:
  - name: Checkout
    uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      fetch-depth: 1
      ref: ${{ github.event.pull_request.head.sha || github.sha }}
      persist-credentials: false

  - name: Use local branch
    shell: bash
    env:
      EVENT_NAME: ${{ github.event_name }}
      HEAD_REF: ${{ github.head_ref }}
      REF_NAME: ${{ github.ref_name }}
    run: |
      if [ "$EVENT_NAME" = "pull_request" ]; then
        BRANCH="$HEAD_REF"
      else
        BRANCH="$REF_NAME"
      fi
      git branch -D "$BRANCH" 2>/dev/null || true
      git branch "$BRANCH" HEAD
      git checkout "$BRANCH"

  - name: Install PHP with extensions
    uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
    with:
      php-version: ${{ env.PHP_VERSION }}
      ini-values: memory_limit=-1, zend.assertions=1, error_reporting=-1, display_errors=On, display_startup_errors=On
      coverage: xdebug
      tools: none

  - name: Get Composer cache directory
    id: composer-cache
    shell: bash
    run: |
      echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

  - name: Cache Composer cache directory
    uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
    with:
      path: ${{ steps.composer-cache.outputs.dir }}
      key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
      restore-keys: ${{ runner.os }}-composer-

  - name: Install dependencies with Composer
    run: ./tools/composer update --no-ansi --no-interaction --no-progress

  - name: Collect code coverage with PHPUnit
    run: vendor/bin/phpunit --log-junit test-results.xml --coverage-openclover=code-coverage.xml

  - name: Upload test results to Codecov.io
    if: ${{ !cancelled() }}
    uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
    with:
      token: ${{ secrets.CODECOV_TOKEN }}
      report_type: test_results
      disable_search: true
      files: ./test-results.xml

  - name: Upload code coverage data to Codecov.io
    if: ${{ !cancelled() }}
    uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
    with:
      token: ${{ secrets.CODECOV_TOKEN }}
      report_type: coverage
      disable_search: true
      files: ./code-coverage.xml

File: .github/workflows/release.yaml

https://docs.github.com/en/actions

on:
push:
tags:
- "**"

name: Release

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: read

jobs:
release:
name: Release

text
runs-on: ubuntu-latest

permissions:
  contents: write # required to create GitHub releases

steps:
  - name: Checkout
    uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      persist-credentials: false

  - name: Install PHP with extensions
    uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
    with:
      php-version: 8.3
      coverage: none
      extensions: none
      tools: none

  - name: Determine tag
    run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

  - name: Parse ChangeLog
    run: build/scripts/extract-release-notes.php "${RELEASE_TAG}" > release-notes.md

  - name: Create release
    env:
      GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    run: gh release create "${RELEASE_TAG}" --title "sebastian/object-reflector ${RELEASE_TAG}" --notes-file release-notes.md