Skip to content

[PropertyAccessor] [DX] - Use bitmask argument to set up throwExceptionOnInvalidIndex and/or throwExceptionOnInvalidPropertyPath #31126

@dimabory

Description

@dimabory

Description
I'd like to have a bitmask argument in the PropertyAccessor constructor. Currently, it's hard to understand on the first sight what each argument means while initializing PropertyAccessor. I know that PropertyAccessor intended not to be used in the application code, but it doesn't prevent to use it anyway.

Related issue #30536

Example

Before:

new PropertyAccessor(
	$magicCall = false, 
	$throwExceptionOnInvalidIndex = false, 
	$cacheItemPool = null, 
	$throwExceptionOnInvalidPropertyPath = false
);

After:

  • By default:
new PropertyAccessor(
	$magicCall = false, 
	$throwExceptionBitmask = 0,
	$cacheItemPool = null
);
  • To throw an exception on the invalid index:
new PropertyAccessor(
	$magicCall = false, 
	$throwExceptionBitmask = PropertyAccessor::THROW_EXCEPTION_ON_INVALID_INDEX, /* THROW_EXCEPTION_ON_INVALID_INDEX = 1 */
	$cacheItemPool = null
);
  • To throw an exception on the invalid property path:
new PropertyAccessor(
	$magicCall = false, 
	$throwExceptionBitmask = PropertyAccessor::THROW_EXCEPTION_ON_INVALID_PROPERTY_PATH, /* THROW_EXCEPTION_ON_INVALID_PROPERTY_PATH = 2 */
	$cacheItemPool = null
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions