Objectiphy
  • Introduction
  • Quick Start
  • Basic Fetching
  • Basic Saving
  • Deleting
  • Mapping Providers
    • Attributes
    • Objectiphy Mapping
    • Doctrine Mapping
  • Defining Relationships
    • One to one
    • One to Many
    • Many to one
    • Many to Many
    • Scalar Joins
  • Query Builder
    • Running a Query
    • Select Queries
    • Update Queries
    • Insert Queries
    • Delete Queries
    • Criteria
      • Operators
      • Filtering by Child Objects
      • Filtering by Aggregates
    • Joins
  • Pagination and Sorting
  • Embedded Value Objects
  • Serialization Groups
  • Late Binding and Lazy Loading
  • Streaming Results
  • Custom Repositories
  • Optimisation
  • Configuration Options
  • Mapping Overrides
  • Caching
  • Comparison with Doctrine
  • Code Generation etc.
  • Troubleshooting
  • Licence, Copyright, Credits
Powered by GitBook
On this page

Was this helpful?

  1. Mapping Providers

Attributes

Starting with PHP 8, we can use attributes instead of annotations!

Objectiphy v2.0 remains backward compatible with PHP 7.4, which did not support attributes as part of the language. Attributes were introduced in PHP 8.0, and they essentially perform the same role that annotations performed before then.

Annotations were just comments in a doc block, had no officially defined syntax, and were completely ignored by PHP - they required a library to read and parse the doc block (typically, Doctrine's annotation reader). As of PHP 8, use of annotations is discouraged, as attributes are now part of the language and are parsed by PHP itself, following officially recognised syntax. This makes them more performant and it becomes much easier to identify syntax errors and prevent bugs.

Objectiphy will continue to support reading annotations indefinitely, but if you are creating new entities, you are strongly encouraged to use attributes instead. If attributes are present on an entity, Objectiphy will not bother checking for annotations (to speed up processing), so do not try to use a mixture of both! In the pages that follow, descriptions are given of mapping definitions for both Objectiphy and Doctrine (just the Doctrine ones that Objectiphy can understand, which is not all of them), and both attribute and annotation syntax are shown in the examples.

PreviousMapping ProvidersNextObjectiphy Mapping

Last updated 2 years ago

Was this helpful?