Oihana PHP System

Product extends Thing

Any offered product or service. For example: a pair of shoes; a concert ticket; the rental of a car; a haircut; or an episode of a TV show streamed online.

Tags
see
https://schema.org/Product

Table of Contents

Constants

CONTEXT  = 'https://schema.org'
JSON-LD @context declaration for Schema.org.
JSON_PRIORITY_KEYS  = [\org\schema\constants\Schema::AT_TYPE, \org\schema\constants\Schema::AT_CONTEXT, \org\schema\constants\Schema::_KEY, \org\schema\constants\Schema::_FROM, \org\schema\constants\Schema::_TO, \org\schema\constants\Schema::ID, \org\schema\constants\Schema::NAME, \org\schema\constants\Schema::URL, \org\schema\constants\Schema::CREATED, \org\schema\constants\Schema::MODIFIED]
Defines the priority order of keys when serializing the object to JSON-LD.

Properties

$_from  : string|null
The metadata to indicates the edge 'from' identifier.
$_id  : null|string
The metadata identifier of the item.
$_key  : null|string
The metadata unique key identifier of the thing.
$_rev  : null|string
The metadata revision value of the thing.
$_to  : string|null
The metadata to indicates the edge 'to' identifier.
$active  : bool|null
The active flag.
$additionalProperty  : null|array<string|int, mixed>|PropertyValue
A property-value pair representing an additional characteristic of the entity, e.g. a product feature or another characteristic for which there is no matching property in schema.org.
$additionalType  : array<string|int, mixed>|string|null|object
An additionalType for the item.
$aggregateRating  : null|array<string|int, mixed>|AggregateRating
The overall rating, based on a collection of reviews or ratings, of the item.
$alternateName  : string|object|array<string|int, mixed>|null
An alias for the item.
$asin  : null|string
An Amazon Standard Identification Number (ASIN) is a 10-character alphanumeric unique identifier assigned by Amazon.com and its partners for product identification within the Amazon organization.
$audience  : null|array<string|int, mixed>|Audience
An intended audience, i.e. a group for whom something was created. Supersedes serviceAudience.
$award  : string|array<string|int, mixed>|null
An award won by or for this item.
$brand  : Brand|Organization|array<string|int, mixed>|null
The brand(s) associated with a product or service, or the brand(s) maintained by an organization or business person.
$category  : null|array<string|int, mixed>|string|CategoryCode|Thing
A category for the item. Greater signs or slashes can be used to informally indicate a category hierarchy.
$color  : string|null
The color of the product.
$colorSwatch  : string|object|null
A color swatch image, visualizing the color of a Product.
$countryOfAssembly  : string|null
The place where the product was assembled.
$countryOfLastProcessing  : string|null
The place where the item (typically Product) was last processed and tested before importation.
$countryOfOrigin  : Country|null
The country of origin of something, including products as well as creative works such as movie and TV content.
$created  : null|string
Date of creation of the resource.
$depth  : float|null
The depth of the item.
$description  : string|object|array<string|int, mixed>|null
A short description of the item.
$disambiguatingDescription  : string|null
A sub property of description. A short description of the item used to disambiguate from other, similar items. Information from other properties (in particular, name) may be necessary for the description to be useful for disambiguation.
$displayLocation  : null|Place|array<string|int, mixed>|string
The location at which an item can be viewed or experienced in-person.
$funding  : string|array<string|int, mixed>|Grant|null
A Grant that directly or indirectly provide funding or sponsorship for this item.
$gtin  : string|null
A correct gtin value should be a valid GTIN, which means that it should be an all-numeric string of either 8, 12, 13 or 14 digits, or a "GS1 Digital Link" URL based on such a string.
$gtin12  : string|null
The GTIN-12 code of the product, or the product to which the offer refers.
$gtin13  : string|null
The GTIN-13 code of the product, or the product to which the offer refers.
$gtin14  : string|null
The GTIN-14 code of the product, or the product to which the offer refers.
$gtin8  : string|null
The GTIN-8 code of the product, or the product to which the offer refers. This code is also known as EAN/UCC-8 or 8-digit EAN.
$hasAdultConsideration  : string|Enumeration|DefinedTerm|array<string|int, mixed>|null
Used to tag an item to be intended or suitable for consumption or use by adults only.
$hasCertification  : null|array<string|int, mixed>|string|Certification
Certification information about a product, organization, service, place, or person.
$hasGS1DigitalLink  : string|null
The GS1 digital link associated with the object.
$hasMeasurement  : null|array<string|int, mixed>|QuantitativeValue
A measurement of an item, For example, the inseam of pants, the wheel size of a bicycle, the gauge of a screw, or the carbon footprint measured for certification by an authority.
$hasMerchantReturnPolicy  : null|array<string|int, mixed>|MerchantReturnPolicy
Specifies a MerchantReturnPolicy that may be applicable.
$hasPart  : string|Thing|array<string|int, Thing>|null
Indicates an item that this part of this item.
$height  : float|null
The height of the item.
$id  : null|int|string
The unique identifier of the item.
$identifier  : string|null
The identifier of the item.
$image  : string|ImageObject|array<string|int, ImageObject|string>|null
The image reference of this resource.
$inProductGroupWithID  : string|null
Indicates the productGroupID for a ProductGroup that this product isVariantOf.
$isAccessoryOrSparePartFor  : null|Product|array<string|int, mixed>
A pointer to another product (or multiple products) for which this product is an accessory or spare part.
$isConsumableFor  : null|Product|array<string|int, mixed>
A pointer to another product (or multiple products) for which this product is a consumable.
$isFamilyFriendly  : bool|null
Indicates whether this content is family friendly.
$isPartOf  : string|Thing|array<string|int, Thing>|null
Indicates an item that this item is part of.
$isRelatedTo  : Product|Service|array<string|int, mixed>|null
A pointer to another, somehow related product (or multiple products).
$isSimilarTo  : Product|Service|array<string|int, mixed>|null
A pointer to another, functionally similar product (or multiple products).
$isVariantOf  : null|array<string|int, mixed>|ProductModel|ProductGroup
Indicates the kind of product that this is a variant of. In the case of ProductModel, this is a pointer (from a ProductModel) to a base product from which this product is a variant.
$itemCondition  : DefinedTerm|string|OfferItemCondition|array<string|int, mixed>|null
A predefined value from OfferItemCondition specifying the condition of the product or service, or the products or services included in the offer.
$keywords  : string|DefinedTerm|array<string|int, mixed>|null
Keywords or tags used to describe some item. Multiple textual entries in a keywords list are typically delimited by commas, or by repeating the property.
$license  : string|object|null
A legal document giving official permission to do something with the resource.
$logo  : string|ImageObject|null
An associated logo.
$mainEntityOfPage  : string|null
Indicates a page (or other CreativeWork) for which this thing is the main entity being described.
$manufacturer  : int|Organization|string|null
The manufacturer of the product.
$material  : array<string|int, mixed>|Product|string|null
A material that something is made from, e.g. leather, wool, cotton, paper.
$mobileUrl  : string|null
The mobileUrl property is provided for specific situations in which data consumers need to determine whether one of several provided URLs is a dedicated 'mobile site'.
$model  : ProductModel|string|null
The model of the product.
$modified  : null|string
Date on which the resource was changed.
$mpn  : string|null
The Manufacturer Part Number (MPN) of the product, or the product to which the offer refers.
$name  : int|string|null
The name of the item.
$negativeNotes  : array<string|int, mixed>|ItemList|ListItem|string|WebContent|null
Provides negative considerations regarding something, most typically in pro/con lists for reviews (alongside positiveNotes). For symmetry
$nsn  : string|null
Indicates the NATO stock number (nsn) of a Product.
$offers  : array<string|int, mixed>|Offer|Demand|null
An offer to provide this item.
$owner  : null|string|Thing
The owner of this Thing.
$pattern  : string|DefinedTerm|null
A pattern that something has, for example 'polka dot', 'striped', 'Canadian flag'. Values are typically expressed as text, although links to controlled value schemes are also supported.
$positiveNotes  : array<string|int, mixed>|ItemList|ListItem|string|WebContent|null
Provides positive considerations regarding something, for example product highlights or (alongside negativeNotes) pro/con lists for reviews.
$potentialAction  : array<string|int, mixed>|Action|null
Indicates a potential Action, which describes an idealized action in which this thing would play an 'object' role.
$productID  : string|null
The product identifier, such as ISBN. For example: meta itemprop="productID" content="isbn:123-456-789".
$productionDate  : string|null|int
The date of production of the item, e.g. vehicle.
$publisher  : string|array<string|int, string|Person|Organization>|Person|Organization|null
The publisher of the resource.
$purchaseDate  : string|int|null
The date the item, e.g. vehicle, was purchased by the current owner.
$releaseDate  : string|int|null
The release date of a product or product model.
$review  : null|array<string|int, mixed>|Review
A review of the item.
$sameAs  : string|array<string|int, mixed>|null
URL of a reference Web page that unambiguously indicates the item's identity.
$size  : null|string|DefinedTerm|QuantitativeValue|SizeSpecification|array<string|int, mixed>
A standardized size of a product or creative work, specified either through a simple textual string (for example 'XL', '32Wx34L'), a QuantitativeValue with a unitCode, or a comprehensive and structured SizeSpecification; in other cases, the width, height, depth and weight properties may be more applicable.
$sku  : string|null
The Stock Keeping Unit (SKU), i.e. a merchant-specific identifier for a product or service, or the product to which the offer refers.
$slogan  : string|null
A slogan or motto associated with the item.
$subjectOf  : null|string|array<string|int, mixed>|CreativeWork|Event
A CreativeWork or Event about this Thing.
$url  : int|string|null
URL of the item.
$weight  : float|null
The weight of the item.
$width  : float|null
The width of the item.
$atContext  : string|null
The JSON-LD `@context` value.
$atType  : string|null
The JSON-LD `@type` value.

Methods

__construct()  : mixed
Constructor to hydrate public properties from an array or stdClass.
jsonSerialize()  : array<string|int, mixed>
Serializes the current object into a JSON-LD array.
withAtContext()  : $this
Sets the internal JSON-LD `@context` attribute.
withAtType()  : $this
Sets the internal JSON-LD `@type` attribute.
withJSONLDMeta()  : $this
Initializes both JSON-LD metadata: `@type` and `@context`.

Constants

CONTEXT

JSON-LD @context declaration for Schema.org.

public mixed CONTEXT = 'https://schema.org'

JSON_PRIORITY_KEYS

Defines the priority order of keys when serializing the object to JSON-LD.

public array<string|int, string> JSON_PRIORITY_KEYS = [\org\schema\constants\Schema::AT_TYPE, \org\schema\constants\Schema::AT_CONTEXT, \org\schema\constants\Schema::_KEY, \org\schema\constants\Schema::_FROM, \org\schema\constants\Schema::_TO, \org\schema\constants\Schema::ID, \org\schema\constants\Schema::NAME, \org\schema\constants\Schema::URL, \org\schema\constants\Schema::CREATED, \org\schema\constants\Schema::MODIFIED]

Keys listed here will always appear first in the serialized array, in the order specified. All remaining public properties will be sorted alphabetically after these priority keys.

This ensures that important JSON-LD metadata and system fields (like @type, @context, _key, id, url, created, modified, etc.) appear at the top of the output for consistency and readability.

Usage:

$orderedKeys = self::JSON_PRIORITY_KEYS;

Notes:

  • Can be overridden in a subclass by redefining the constant.
  • Late static binding (static::JSON_PRIORITY_KEYS) allows child classes to modify the serialization order.

List of JSON-LD keys in priority order.

Properties

$_from

The metadata to indicates the edge 'from' identifier.

public string|null $_from

$_id

The metadata identifier of the item.

public null|string $_id

$_key

The metadata unique key identifier of the thing.

public null|string $_key

$_rev

The metadata revision value of the thing.

public null|string $_rev

$_to

The metadata to indicates the edge 'to' identifier.

public string|null $_to

$active

The active flag.

public bool|null $active

$additionalProperty

A property-value pair representing an additional characteristic of the entity, e.g. a product feature or another characteristic for which there is no matching property in schema.org.

public null|array<string|int, mixed>|PropertyValue $additionalProperty = null
Attributes
#[HydrateWith]
\org\schema\PropertyValue::class

$additionalType

An additionalType for the item.

public array<string|int, mixed>|string|null|object $additionalType

$aggregateRating

The overall rating, based on a collection of reviews or ratings, of the item.

public null|array<string|int, mixed>|AggregateRating $aggregateRating
Attributes
#[HydrateWith]
\org\schema\AggregateRating::class

$alternateName

An alias for the item.

public string|object|array<string|int, mixed>|null $alternateName

$asin

An Amazon Standard Identification Number (ASIN) is a 10-character alphanumeric unique identifier assigned by Amazon.com and its partners for product identification within the Amazon organization.

public null|string $asin

$audience

An intended audience, i.e. a group for whom something was created. Supersedes serviceAudience.

public null|array<string|int, mixed>|Audience $audience
Attributes
#[HydrateWith]
\org\schema\Audience::class

$award

An award won by or for this item.

public string|array<string|int, mixed>|null $award

$brand

The brand(s) associated with a product or service, or the brand(s) maintained by an organization or business person.

public Brand|Organization|array<string|int, mixed>|null $brand

$category

A category for the item. Greater signs or slashes can be used to informally indicate a category hierarchy.

public null|array<string|int, mixed>|string|CategoryCode|Thing $category

$color

The color of the product.

public string|null $color

$colorSwatch

A color swatch image, visualizing the color of a Product.

public string|object|null $colorSwatch

Should match the textual description specified in the color property. This can be a URL or a fully described ImageObject.

$countryOfAssembly

The place where the product was assembled.

public string|null $countryOfAssembly

$countryOfLastProcessing

The place where the item (typically Product) was last processed and tested before importation.

public string|null $countryOfLastProcessing

$countryOfOrigin

The country of origin of something, including products as well as creative works such as movie and TV content.

public Country|null $countryOfOrigin

In the case of TV and movie, this would be the country of the principle offices of the production company or individual responsible for the movie. For other kinds of CreativeWork it is difficult to provide fully general guidance, and properties such as contentLocation and locationCreated may be more applicable.

In the case of products, the country of origin of the product. The exact interpretation of this may vary by context and product type, and cannot be fully enumerated here.

$created

Date of creation of the resource.

public null|string $created

$depth

The depth of the item.

public float|null $depth

$description

A short description of the item.

public string|object|array<string|int, mixed>|null $description

$disambiguatingDescription

A sub property of description. A short description of the item used to disambiguate from other, similar items. Information from other properties (in particular, name) may be necessary for the description to be useful for disambiguation.

public string|null $disambiguatingDescription

$displayLocation

The location at which an item can be viewed or experienced in-person.

public null|Place|array<string|int, mixed>|string $displayLocation

$funding

A Grant that directly or indirectly provide funding or sponsorship for this item.

public string|array<string|int, mixed>|Grant|null $funding

$gtin

A correct gtin value should be a valid GTIN, which means that it should be an all-numeric string of either 8, 12, 13 or 14 digits, or a "GS1 Digital Link" URL based on such a string.

public string|null $gtin

The numeric component should also have a valid GS1 check digit and meet the other rules for valid GTINs.

$gtin12

The GTIN-12 code of the product, or the product to which the offer refers.

public string|null $gtin12

The GTIN-12 is the 12-digit GS1 Identification Key composed of a U.P.C. Company Prefix, Item Reference, and Check Digit used to identify trade items.

$gtin13

The GTIN-13 code of the product, or the product to which the offer refers.

public string|null $gtin13

This is equivalent to 13-digit ISBN codes and EAN UCC-13. Former 12-digit UPC codes can be converted into a GTIN-13 code by simply adding a preceding zero.

$gtin14

The GTIN-14 code of the product, or the product to which the offer refers.

public string|null $gtin14

$gtin8

The GTIN-8 code of the product, or the product to which the offer refers. This code is also known as EAN/UCC-8 or 8-digit EAN.

public string|null $gtin8

$hasAdultConsideration

Used to tag an item to be intended or suitable for consumption or use by adults only.

public string|Enumeration|DefinedTerm|array<string|int, mixed>|null $hasAdultConsideration

Example:

  • AlcoholConsideration
  • DangerousGoodConsideration
  • HealthcareConsideration
  • NarcoticConsideration
  • ReducedRelevanceForChildrenConsideration
  • SexualContentConsideration
  • TobaccoNicotineConsideration
  • UnclassifiedAdultConsideration
  • ViolenceConsideration
  • WeaponConsideration

$hasCertification

Certification information about a product, organization, service, place, or person.

public null|array<string|int, mixed>|string|Certification $hasCertification
Attributes
#[HydrateWith]
\org\schema\creativeWork\Certification::class

The GS1 digital link associated with the object.

public string|null $hasGS1DigitalLink

This URL should conform to the particular requirements of digital links. The link should only contain the Application Identifiers (AIs) that are relevant for the entity being annotated, for instance a Product or an Organization, and for the correct granularity.

$hasMeasurement

A measurement of an item, For example, the inseam of pants, the wheel size of a bicycle, the gauge of a screw, or the carbon footprint measured for certification by an authority.

public null|array<string|int, mixed>|QuantitativeValue $hasMeasurement

Usually an exact measurement, but can also be a range of measurements for adjustable products, for example belts and ski bindings.

Attributes
#[HydrateWith]
\org\schema\QuantitativeValue::class

$hasMerchantReturnPolicy

Specifies a MerchantReturnPolicy that may be applicable.

public null|array<string|int, mixed>|MerchantReturnPolicy $hasMerchantReturnPolicy

$hasPart

Indicates an item that this part of this item.

public string|Thing|array<string|int, Thing>|null $hasPart

$height

The height of the item.

public float|null $height

$id

The unique identifier of the item.

public null|int|string $id

$identifier

The identifier of the item.

public string|null $identifier

$inProductGroupWithID

Indicates the productGroupID for a ProductGroup that this product isVariantOf.

public string|null $inProductGroupWithID

$isAccessoryOrSparePartFor

A pointer to another product (or multiple products) for which this product is an accessory or spare part.

public null|Product|array<string|int, mixed> $isAccessoryOrSparePartFor
Attributes
#[HydrateWith]
\org\schema\Product::class

$isConsumableFor

A pointer to another product (or multiple products) for which this product is a consumable.

public null|Product|array<string|int, mixed> $isConsumableFor
Attributes
#[HydrateWith]
\org\schema\Product::class

$isFamilyFriendly

Indicates whether this content is family friendly.

public bool|null $isFamilyFriendly

$isPartOf

Indicates an item that this item is part of.

public string|Thing|array<string|int, Thing>|null $isPartOf

$isRelatedTo

A pointer to another, somehow related product (or multiple products).

public Product|Service|array<string|int, mixed>|null $isRelatedTo

$isSimilarTo

A pointer to another, functionally similar product (or multiple products).

public Product|Service|array<string|int, mixed>|null $isSimilarTo

$isVariantOf

Indicates the kind of product that this is a variant of. In the case of ProductModel, this is a pointer (from a ProductModel) to a base product from which this product is a variant.

public null|array<string|int, mixed>|ProductModel|ProductGroup $isVariantOf
Attributes
#[HydrateWith]
\org\schema\ProductModel::class
\org\schema\ProductGroup::class

$itemCondition

A predefined value from OfferItemCondition specifying the condition of the product or service, or the products or services included in the offer.

public DefinedTerm|string|OfferItemCondition|array<string|int, mixed>|null $itemCondition

Also used for product return policies to specify the condition of products accepted for returns. Example:

  • DamagedCondition
  • NewCondition
  • RefurbishedCondition
  • UsedCondition

$keywords

Keywords or tags used to describe some item. Multiple textual entries in a keywords list are typically delimited by commas, or by repeating the property.

public string|DefinedTerm|array<string|int, mixed>|null $keywords

$license

A legal document giving official permission to do something with the resource.

public string|object|null $license

$mainEntityOfPage

Indicates a page (or other CreativeWork) for which this thing is the main entity being described.

public string|null $mainEntityOfPage

$manufacturer

The manufacturer of the product.

public int|Organization|string|null $manufacturer

$material

A material that something is made from, e.g. leather, wool, cotton, paper.

public array<string|int, mixed>|Product|string|null $material

$mobileUrl

The mobileUrl property is provided for specific situations in which data consumers need to determine whether one of several provided URLs is a dedicated 'mobile site'.

public string|null $mobileUrl

$modified

Date on which the resource was changed.

public null|string $modified

$mpn

The Manufacturer Part Number (MPN) of the product, or the product to which the offer refers.

public string|null $mpn

$name

The name of the item.

public int|string|null $name

$negativeNotes

Provides negative considerations regarding something, most typically in pro/con lists for reviews (alongside positiveNotes). For symmetry

public array<string|int, mixed>|ItemList|ListItem|string|WebContent|null $negativeNotes

In the case of a Review, the property describes the itemReviewed from the perspective of the review; in the case of a Product, the product itself is being described. Since product descriptions tend to emphasise positive claims, it may be relatively unusual to find negativeNotes used in this way. Nevertheless for the sake of symmetry, negativeNotes can be used on Product.

The property values can be expressed either as unstructured text (repeated as necessary), or if ordered, as a list (in which case the most negative is at the beginning of the list).

$offers

An offer to provide this item.

public array<string|int, mixed>|Offer|Demand|null $offers
Attributes
#[HydrateWith]
\org\schema\Offer::class
\org\schema\Demand::class

$owner

The owner of this Thing.

public null|string|Thing $owner

Represents any entity (person, organization, system, or other object) that can be considered the possessor of this Thing.

$pattern

A pattern that something has, for example 'polka dot', 'striped', 'Canadian flag'. Values are typically expressed as text, although links to controlled value schemes are also supported.

public string|DefinedTerm|null $pattern

$positiveNotes

Provides positive considerations regarding something, for example product highlights or (alongside negativeNotes) pro/con lists for reviews.

public array<string|int, mixed>|ItemList|ListItem|string|WebContent|null $positiveNotes

In the case of a Review, the property describes the itemReviewed from the perspective of the review; in the case of a Product, the product itself is being described.

The property values can be expressed either as unstructured text (repeated as necessary), or if ordered, as a list (in which case the most positive is at the beginning of the list).

$potentialAction

Indicates a potential Action, which describes an idealized action in which this thing would play an 'object' role.

public array<string|int, mixed>|Action|null $potentialAction

$productID

The product identifier, such as ISBN. For example: meta itemprop="productID" content="isbn:123-456-789".

public string|null $productID

$productionDate

The date of production of the item, e.g. vehicle.

public string|null|int $productionDate

$purchaseDate

The date the item, e.g. vehicle, was purchased by the current owner.

public string|int|null $purchaseDate

$releaseDate

The release date of a product or product model.

public string|int|null $releaseDate

This can be used to distinguish the exact variant of a product.

$review

A review of the item.

public null|array<string|int, mixed>|Review $review
Attributes
#[HydrateWith]
\org\schema\Review::class

$sameAs

URL of a reference Web page that unambiguously indicates the item's identity.

public string|array<string|int, mixed>|null $sameAs

E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.

$size

A standardized size of a product or creative work, specified either through a simple textual string (for example 'XL', '32Wx34L'), a QuantitativeValue with a unitCode, or a comprehensive and structured SizeSpecification; in other cases, the width, height, depth and weight properties may be more applicable.

public null|string|DefinedTerm|QuantitativeValue|SizeSpecification|array<string|int, mixed> $size
Attributes
#[HydrateWith]
\org\schema\DefinedTerm::class
\org\schema\QuantitativeValue::class
\org\schema\SizeSpecification::class

$sku

The Stock Keeping Unit (SKU), i.e. a merchant-specific identifier for a product or service, or the product to which the offer refers.

public string|null $sku

$slogan

A slogan or motto associated with the item.

public string|null $slogan

$subjectOf

A CreativeWork or Event about this Thing.

public null|string|array<string|int, mixed>|CreativeWork|Event $subjectOf

$url

URL of the item.

public int|string|null $url

$weight

The weight of the item.

public float|null $weight

$width

The width of the item.

public float|null $width

$atContext

The JSON-LD `@context` value.

private string|null $atContext = null

Default is https://schema.org.

$atType

The JSON-LD `@type` value.

private string|null $atType = null

This can be manually set or automatically inferred from the class name.

Methods

__construct()

Constructor to hydrate public properties from an array or stdClass.

public __construct([array<string|int, mixed>|object|null $init = null ]) : mixed

This allows objects to be quickly populated with associative data without manually setting each property.

Parameters
$init : array<string|int, mixed>|object|null = null

A data array or object used to initialize the instance. Keys must match public property names.

Tags
throws
ReflectionException
example
use org\schema\Person;
use org\schema\constants\Prop;

$person = new Person
([
    Prop::NAME => 'Jane Doe',
    Prop::URL  => 'https://example.com/janedoe'
]);

echo $person->name; // Outputs: Jane Doe

jsonSerialize()

Serializes the current object into a JSON-LD array.

public jsonSerialize() : array<string|int, mixed>

Includes public properties, the JSON-LD @context and @type. Null values are automatically removed.

Tags
throws
ReflectionException

If reflection fails when accessing properties.

example
use org\schema\Person;
use org\schema\constants\Prop;

$person = new Person
([
    Prop::NAME => 'John Smith',
    Prop::ID   => 'jsmith-001'
]);

echo json_encode($person, JSON_PRETTY_PRINT);

Output:

{
   "@type": "Person",
   "@context": "https://schema.org",
   "id": "jsmith-001",
   "name": "John Smith"
}
Return values
array<string|int, mixed>

JSON-LD representation of the object.

withAtContext()

Sets the internal JSON-LD `@context` attribute.

public withAtContext(string $context) : $this

Useful if you need a custom JSON-LD context.

Parameters
$context : string

Optional JSON-LD context.

Return values
$this

withAtType()

Sets the internal JSON-LD `@type` attribute.

public withAtType(string $type) : $this

Allows overriding the default type inferred from the class.

Parameters
$type : string

Optional JSON-LD type

Return values
$this

withJSONLDMeta()

Initializes both JSON-LD metadata: `@type` and `@context`.

public withJSONLDMeta([string|null $atType = null ][, string|null $atContext = null ]) : $this

Can be called from constructor or later to override default values.

Parameters
$atType : string|null = null

Optional JSON-LD type

$atContext : string|null = null

Optional JSON-LD context

Return values
$this

        
On this page

Search results