Skip to content

Properties (hooks) Other features that can be implemented in php 8.5 #17436

Description

@wnunezc

Description

Description
Referenced RFC #13455

The following code:https://3v4l.org/5eEWn#v8.3.15

<?php///on php version < 8.4class Foo
{
private$data = null;
publicfunctionissetData(){
return$this->data !== null;
}
publicfunctionsetData($data){
$this->data = $data;
}
}
$foo = newFoo();
var_dump($foo->issetData());
$foo->setData(123);
var_dump($foo->issetData());

output:

bool(false)
bool(true)


With the implementation of the Properties Hook we should be able to: https://3v4l.org/QtIpg#v8.4.2

<?phpclass Foo
{
publicmixed$data {
get => $this->data ?? null; //throw new Exception("this property is not set.");
set => $this->data = $value;
}
publicfunctionissetData(){
returnisset($this->data);
}
}
$foo = newFoo();
var_dump($foo->issetData());
var_dump($foo->data);
$foo->data = 'Hello World!!!';
var_dump($foo->issetData());
var_dump($foo->data);

output:

bool(false)
NULL
bool(true)
string(14) "Hello World!!!"

I think this is still halfway there, I think I should be able to do this:

https://3v4l.org/Q6Ep9#v8.4.2

<?phpclass Foo
{
publicmixed$data {
get => $this->data ?? null; //throw new Exception("this property is not set.");
set => $this->data = $value;
isset => isset($this->data);
}
}
$foo = newFoo();
//option 1var_dump(?$foo->data); // This should produce the same output as an "isset" implemente "?" at begining// Expected output: false//option 2var_dump($foo->data?isset); // This should join on "isset" hook, implement ?isset at end// Expected output: false//Option 3: Create a shorthand symbol for isset like the two examples above but without the hook

would it be possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions