Skip to content

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

Closed as not planned
@arcanisgk

Description

@arcanisgk

Description

Description
Referenced RFC #13455

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

<?php
///on php version < 8.4
class Foo
{
    private $data = null;
    public function issetData(){
        return $this->data !== null;
    }
    public function setData($data){
        $this->data = $data;
    }
}

$foo = new Foo();

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

<?php

class Foo
{

    public mixed $data {
        get => $this->data ?? null; //throw new Exception("this property is not set.");
        set => $this->data = $value;
    }
    
    public function issetData(){
        return isset($this->data);
    }
}


$foo = new Foo();

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

<?php

class Foo
{

    public mixed $data {
        get => $this->data ?? null; //throw new Exception("this property is not set.");
        set => $this->data = $value;
        isset => isset($this->data);
    }
}

$foo = new Foo();

//option 1

var_dump(?$foo->data); // This should produce the same output as an "isset" implemente "?" at begining
// Expected output: false

//option 2

var_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