小儿咳嗽吃什么药好| stories是什么意思| 减肥期间晚上吃什么| 吐槽什么意思| 梦见抢银行是什么意思| 什么东西越洗越脏脑筋急转弯| 一个h是什么牌子| 吃什么食物可以去湿气| 什么是口交| enne是什么烟| 手臂长斑是什么原因| 六月是什么星座的| 三庭五眼是什么意思| 生地黄是什么| 牡丹鹦鹉吃什么| 7月1号是什么节| 梦见好多猫是什么预兆| et是什么意思| 清明节吃什么好| 闻香识女人是什么意思| 风寒感冒流鼻涕吃什么药| 吃天麻对身体有什么好处| 为什么会卵巢早衰| 小河边有什么| 什么水适合婴儿冲奶粉| 强的松是什么药| 无国界医生是什么意思| 大表哥是什么游戏| 平权是什么意思| 平安夜送女朋友什么| 吐槽什么意思| 什么病需要透析| 痔疮手术后可以吃什么水果| 3月19日什么星座| 脑膜炎吃什么药| 米面是什么| 骑士是什么意思| 改善记忆力吃什么药好| 狗又吐又拉稀吃什么药| 24号来月经什么时候是排卵期| 中项是什么意思| 瘦脱相是什么意思| 梦见和别人打架是什么意思| ot是什么| 琛读什么| ph值是什么| 章鱼属于什么类动物| 耳朵疼吃什么消炎药| 什么门不能开| 毛囊是什么样子图片| 肌肉痛吃什么药| 为什么月经前乳房胀痛| 吃什么油最健康排行榜| 肺纹理增粗是什么意思| 怦然心动什么意思| 安宫牛黄丸什么时候吃| 梦见吃豆腐是什么意思| 晚上胃疼是什么原因| spoRT是什么| 性感染有什么症状| 吃了避孕药不能吃什么东西| 关东煮为什么叫关东煮| 八面玲珑指什么生肖| 吃维生素b6有什么好处和副作用| 什么一梦| 肺炎吃什么药| 经信局是干什么的| 宝贝疙瘩是什么意思| 一心向阳下一句是什么| 白斑是什么病| 脊柱疼是什么原因| 生命的尽头是什么| 梦见游泳是什么预兆| 五味指的是什么| ppap是什么| 吃什么最补胶原蛋白| 太阳什么的什么的| 深闺是什么意思| 解脲脲原体阳性是什么意思| 合成革是什么材质| 果代表什么生肖| 肉苁蓉有什么功效| 腰酸是什么病的前兆| 抑郁症是什么原因造成| 吃什么能补雌激素| 边沿是什么意思| 胃酸吃什么| 神经酸是什么| 六是什么意思| 平均红细胞体积偏低是什么原因| 惊为天人是什么意思| 梦见父母是什么意思| 猫喜欢什么样的人| 米果念什么| 放屁特别臭是什么原因| 小三阳吃什么食物好得快| 生姜和红糖熬水有什么作用| smr是什么意思| 天山童姥练的什么武功| 发炎是什么意思| 胆固醇偏高是什么意思| 非那雄胺片是什么药| 手指甲软薄是缺什么| 桑树枝煮水有什么功效| 尿蛋白质阳性是什么意思| 心慌心跳吃什么药| 白细胞低是怎么回事有什么危害| 什么是中位数| 梦见着大火了是什么征兆| 路引是什么| 多吃什么可以长头发| 老年人便秘吃什么药| 艾字五行属什么| 喝生姜水有什么好处| 血糖高喝什么豆浆好| 周遭是什么意思| 不丹为什么不跟中国建交| 但愿是什么意思| 碱性磷酸酶高是什么原因| 山珍海味是什么意思| cba新赛季什么时候开始| 胃肠炎可以吃什么水果| 经信局是做什么的| 疝气吃什么药效果好| 四月二十九是什么星座| 包粽子用什么米| 蜘蛛怕什么| 肌肉萎缩挂什么科| 二氧化碳结合力是什么| 阁是什么意思| 人工周期是什么意思| 对唔嗨住什么意思| 算力是什么| 六味地黄丸什么时候吃最好| 罗盘是干什么用的| 紫癜是一种什么病| 动车跟高铁有什么区别| 小孩子发烧手脚冰凉是什么原因| 7月15日是什么节| 吃什么水果可以降火| 四级什么时候报名| 跑男什么时候播出| 后背沉重感是什么原因引起的| 血常规crp是什么意思| 梦见牛肉有什么征兆| 小腿疼痛挂什么科| 自律是什么意思| 缺蛋白质吃什么补得快| 米氮平是什么药| 早搏吃什么药最好| 快递什么时候上班| 立秋抓秋膘吃什么| 猫驱虫药什么牌子好| 佝偻病是什么病| 砖红色是什么颜色| 早晨起床口苦是什么原因| 脚趾甲真菌感染用什么药| 乳腺增生吃什么药效果好| 偏激是什么意思| 尿蛋白高是什么意思| 梅杰综合症是什么病| 红颜薄命的意思是什么| 胃胀是什么感觉| 鸽子怕什么怎么赶走| 什么是沙棘| 死去活来是什么生肖| 孛儿只斤现在姓什么| 飞鱼籽是什么鱼的籽| 梦见蛇是什么预兆| 节度使是什么意思| 什么是津液| 什么是阴道| model是什么意思| 流鼻血挂什么科| 秋葵有什么作用| 血栓吃什么药| 普洱茶属于什么茶| 5月7日是什么星座| 嘴唇红是什么原因| 锅贴是什么| loser是什么意思| 手掌痒是什么原因| 9五行属什么| 瑜伽是什么| dw手表是什么档次| 9.21是什么星座| ENBD手术全称是什么| 孕吐什么时候出现| 白咖啡是什么| 特点是什么意思| 心律不齐吃什么药好| syphilis是什么意思| 金粉是什么| 泰国有什么好玩| 国防科技大学毕业是什么军衔| advil是什么药| 正的五行属性是什么| 忌口是什么意思| 圣罗兰为什么叫杨树林| 寻麻疹是什么症状| 夜里12点是什么时辰| 肠胃不好挂什么科| 禄位是什么意思| 鸡喜欢吃什么食物| 眼角长脂肪粒是什么原因| 龟头炎什么症状| 花序是什么意思| 省公安厅副厅长是什么级别| 吃避孕药会有什么副作用| 备孕期间不能吃什么| 有待提高是什么意思| 体内湿气重用什么药| 草酸是干什么用的| 安居乐业什么意思| 吃完虾不能吃什么水果| 白内障什么症状| 检查肾功能挂什么科| 巨蟹座和什么星座最配| 爱母环是什么形状图片| 香菜什么时候种最合适| 靶向药物是什么| cpi是什么意思啊| cmb是什么意思| 二个月不来月经是什么原因| 违心的话是什么意思| 什么是腺体| 赤脚走路有什么好处| 吃了虾不能吃什么水果| 唱反调是什么意思| pc是什么材质| 木耳菜不能和什么一起吃| 排尿困难是什么原因| 女人缺铁性贫血吃什么好| 狮子座是什么象星座| 阳历1月份是什么星座| h202阳性是什么意思| 床塌了有什么预兆| 什么牌子的电饭锅好| 局部是什么意思| 丙肝有什么症状表现| 心脏除颤是什么意思| 有机物是什么| 老火是什么意思| 男人左眼跳是什么意思| 感染hpv吃什么药| dp是什么意思| 黄芪长什么样子的图片| 头痛去医院挂什么科| 大洋马是什么意思| 用你的手解我的锁是什么歌| apc药片是什么药| 武松是什么生肖| 粉红色泡沫样痰是什么病| 氯雷他定片什么时候吃| 威士忌什么味道| 为什么不敢挖雍正陵墓| 杏仁和什么不能一起吃| 水落石出是什么意思| 燕窝什么时候吃最好| 右肾结晶是什么意思| 刺梨是什么水果| 情感障碍是什么意思| 吃什么瘦肚子| msm是什么意思| 百度
rfc:records

女人什么时候最想男人

Introduction

百度 “佛系”商旅除了iPad你还能选这些平板●佛系商旅首选:iPadmini4苹果iPadmini4延续iPadmini系列小身材高性能的优势,其采用的A8芯片赋予iPadmini4更多非凡能力,让你可以走到哪里,用到哪里。

This RFC proposes the introduction of record objects, which are immutable classes with value semantics.

Value objects

Value objects are immutable objects that represent a value. They’re used to store values with a different semantic by wrapping their technical value, adding additional context. For example, a Point object with x and y properties can represent a point in a 2D space, and an ExpirationDate can represent a date when something expires. This prevents developers from accidentally using the wrong value in the wrong context.

Consider this example where a function accepts an integer as a user ID, and the ID is accidentally set to a nonsensical value:

function updateUserRole(int $userId, string $role): void {
    // ...
}
 
$user = getUser(/*...*/)
$uid = $user->id;
// ...
$uid = 5; // accidentally sets uid to an unrelated integer
// ...
updateUserRole($uid, 'admin'); // accidental passes a nonsensical value for uid

Currently, the only solution to this is to use a class, but this requires significant boilerplate code. Further, readonly classes have many edge cases and are rather unwieldy.

The solution

Like arrays, strings, and other values, record objects are strongly equal (===) to each other if they contain the same values.

Let’s take a look at an updated example using a record type for UserId. Thus, if someone were to pass an int to updateUserRole, it would throw an error:

record UserId(int $id);
 
function updateUserRole(UserId $userId, string $role): void {
    // ...
}
 
$user = getUser(/*...*/)
$uid = $user->id; // $uid is a UserId object
// ...
$uid = 5;
// ...
updateUserRole($uid, 'admin'); // This will throw a TypeError

Now, if $uid is accidentally set to an integer, the call to updateUserRole will throw a TypeError because the function expects a UserId object instead of a plain integer.

Proposal

This RFC proposes the introduction of a record keyword in PHP to define immutable value objects. These objects will allow properties to be initialized concisely and will provide built-in methods for common operations such as modifying properties, performing equality checks, and using a function-like instantiation syntax. Records can implement interfaces and use traits but can’t extend other records or classes; composition is allowed, however.

Syntax and semantics

Definition

A record is defined by the keyword record, followed by the name of its type (e.g., UserId), and then must list one or more typed parameters (e.g., int $id) that become properties of the record. A parameter may provide private or public modifiers, but are public when not specified. This is referred to as the “inline constructor.”

A record may optionally implement an interface using the implements keyword, which may optionally be followed by a record body enclosed in curly braces {}.

A record may not extend another record or class.

A record may contain a traditional constructor with zero arguments to perform further initialization.

A record body may contain property hooks, methods, and use traits.

A record body may also declare properties whose values are only mutable during a constructor call. At any other time, the property is immutable.

A record body may also contain static methods and properties, which behave identically to static methods and properties in classes. They may be accessed using the :: operator.

As an example, the following code defines a record named Pigment to represent a color, StockPaint to represent paint colors in stock, and PaintBucket to represent a collection of stock paints mixed together. The actual behavior isn’t important, but illustrates the syntax and semantics of records.

namespace Paint;
 
// Define a record with several primary color properties
record Pigment(int $red, int $yellow, int $blue) {
 
  // property hooks are allowed
  public string $hexValue {
    get => sprintf("#%02x%02x%02x", $this->red, $this->yellow, $this->blue),
  }
 
  // methods are allowed
  public function mix(Pigment $other, float $amount): Pigment {
    return $this->with(
      red: $this->red * (1 - $amount) + $other->red * $amount,
      yellow: $this->yellow * (1 - $amount) + $other->yellow * $amount,
      blue: $this->blue * (1 - $amount) + $other->blue * $amount
    );
  }
 
  // all properties are mutable in constructors
  public function __construct() {
    $this->red = max(0, min(255, $this->red));
    $this->yellow = max(0, min(255, $this->yellow));
    $this->blue = max(0, min(255, $this->blue));
  }
 
  public function with() {
    // prevent the creation of a new Pigment from an existing pigment
    throw new \LogicException("Cannot create a new Pigment from an existing pigment");
  }
}
 
// simple records do not need to define a body
record StockPaint(Pigment $color, float $volume);
 
record PaintBucket(StockPaint ...$constituents) {
  public function mixIn(StockPaint $paint): PaintBucket {
    return $this->with(...[...$this->constituents, $paint]);
  }
 
  public function color(): Pigment {
    return array_reduce($this->constituents, fn($color, $paint) => $color->mix($paint->color, $paint->volume), Pigment(0, 0, 0));
  }
}

Usage

A record may be used much like a class, as the behavior of the two is very similar, assisting in migrating from one implementation to another:

$gray = $bucket->mixIn($blackPaint)->mixIn($whitePaint);

Records are instantiated in a function format, with & prepended. This provides visual feedback that a record is being created instead of a function call.

$black = &Pigment(0, 0, 0);
$white = &Pigment(255, 255, 255);
$blackPaint = &StockPaint($black, 1);
$whitePaint = &StockPaint($white, 1);
$bucket = &PaintBucket();
 
$gray = $bucket->mixIn($blackPaint)->mixIn($whitePaint);
$grey = $bucket->mixIn($blackPaint)->mixIn($whitePaint);
 
assert($gray === $grey); // true

Optional parameters and default values

A record can also be defined with optional parameters that are set if omitted during instantiation.

One or more properties defined in the inline constructor may have a default value declared using the same syntax and rules as any other default parameter in methods/functions. If a property has a default value, it is optional when instantiating the record, and PHP will assign the default value to the property if omitted.

record Rectangle(int $x, int $y = 10);
var_dump(&Rectangle(10)); // output a record with x: 10 and y: 10

Auto-generated with method

To make records more useful, the RFC proposes generating a with method for each record. This method allows for partial updates to the properties, creating a new instance of the record with the specified properties updated.

How the with method works

Named arguments

The with method accepts only named arguments defined in the inline constructor. Properties not defined in the inline constructor can’t be updated by this method.

Variadic arguments

Variadic arguments from the inline constructor don’t require named arguments in the with method. However, mixing named and variadic arguments in the same with method call is not allowed by PHP syntax.

Using named arguments:

record UserId(int $id) {
  public string $serialNumber;
 
  public function __construct() {
    $this->serialNumber = "U{$this->id}";
  }
}
 
$userId = &UserId(1);
$otherId = $userId->with(2); // Fails: Named arguments must be used
$otherId = $userId->with(serialNumber: "U2"); // Error: serialNumber is not defined in the inline constructor
$otherId = $userId->with(id: 2); // Success: id is updated

Using variadic arguments:

record Vector(int $dimensions, int ...$values);
 
$vector = &Vector(3, 1, 2, 3);
$vector = $vector->with(dimensions: 4); // Success: values are updated
$vector = $vector->with(dimensions: 4, 1, 2, 3, 4); // Error: mixing named arguments with variadic arguments is not allowed by PHP syntax
$vector = $vector->with(dimensions: 4)->with(1, 2, 3, 4); // Success: First update dimensions, then values
Custom with method

A developer may define their own with method if they choose, and reference the generated with method using parent::with(). This allows a developer to define policies or constraints on how data can change from instance to instance.

record Planet(string $name, int $population) {
  // create a with method that only accepts population updates
  public function with(int $population): Planet {
    return parent::with(population: $population);
  }
}
$pluto = Planet("Pluto", 0);
// we made it!
$pluto = $pluto->with(population: 1);
// and then we changed the name
$mickey = $pluto->with(name: "Mickey"); // Error: no named argument for population

Constructors

A record has two types of constructors: the inline constructor and the traditional constructor.

The inline constructor is always required and must define at least one parameter. The traditional constructor is optional and can be used for further initialization logic, but must not accept any arguments.

When a traditional constructor exists and is called, the properties are already initialized to the values from the inline constructor and are mutable until the end of the method, at which point they become immutable.

// Inline constructor defining two properties
record User(string $name, string $emailAddress) {
  public string $id;
 
  // Traditional constructor
  public function __construct() {
    if (!is_valid_email($this->emailAddress)) {
      throw new InvalidArgumentException("Invalid email address");
    }
 
    $this->id = hash('sha256', $this->emailAddress);
    $this->name = ucwords($this->name);
    // all properties are now immutable
  }
}

Implementing Interfaces

A record can implement interfaces, but it cannot extend other records or classes, but may use traits:

interface Vehicle {}
 
interface Car extends Vehicle {
  public function drive(): void;
}
 
interface SpaceShip extends Vehicle {
  public function launch(): void;
}
 
record FancyCar(string $model) implements Car {
  public function drive(): void {
    echo "Driving a Fancy Car {$this->model}";
  }
}
 
record SpaceCar(string $model) implements Car, SpaceShip {
  public function drive(): void {
    echo "Driving a Space Car {$this->model}";
  }
 
  public function launch(): void {
    echo "Launching a Space Car {$this->model}";
  }
}
 
record Submarine(string $model) implements Vehicle {
  use Submersible;
}
 
record TowTruct(string $model, private Car $towing) implements Car {
  use Towable;
}

Mental models and how it works

From the perspective of a developer, declaring a record declares an object with the same name. The developer can consider the record function (the inline constructor) as a factory function that creates a new object or retrieves an existing object from an array.

For example, this would be a valid mental model for a Point record:

record Point(int $x, int $y) {
    public float $magnitude;
 
    public function __construct() {
        $this->magnitude = sqrt($this->x ** 2 + $this->y ** 2);
    }
 
    public function add(Point $point): Point {
        return &Point($this->x + $point->x, $this->y + $point->y);
    }
 
    public function dot(Point $point): int {
        return $this->x * $point->x + $this->y * $point->y;
    }
}
 
// similar to declaring the following function and class
 
// used during construction to allow mutability
class Point_Implementation {
    public int $x;
    public int $y;
    public float $magnitude;
 
    public function __construct() {
        $this->magnitude = sqrt($this->x ** 2 + $this->y ** 2);
    }
 
    public function with(...$parameters) {
        // validity checks omitted for brevity
        $parameters = array_merge([$this->x, $this->y], $parameters);
        return Point(...$parameters);
    }
 
    public function add(Point $point): Point {
        return Point($this->x + $point->x, $this->y + $point->y);
    }
 
    public function dot(Point $point): int {
        return $this->x * $point->x + $this->y * $point->y;
    }
}
 
// used to enforce immutability but has nearly the same implementation
readonly class Point {
    public float $magnitude;
 
    public function __construct(public int $x, public int $y) {}
 
    public function with(...$parameters): self {
        // validity checks omitted for brevity
        $parameters = array_merge([$this->x, $this->y], $parameters);
        return Point(...$parameters);
    }
 
    public function add(Point $point): Point {
        return Point($this->x + $point->x, $this->y + $point->y);
    }
 
    public function dot(Point $point): int {
        return $this->x * $point->x + $this->y * $point->y;
    }
}
 
function Point(int $x, int $y): Point {
    static $points = [];
 
    $key = hash_object($mutablePoint);
    if ($points[$key] ?? null) {
        // return an existing point
        return $points[$key];
    }
 
    // create a new point
    $reflector = new \ReflectionClass(Point_Implementation::class);
    $mutablePoint = $reflector->newInstanceWithoutConstructor();
    $mutablePoint->x = $x;
    $mutablePoint->y = $y;
    $mutablePoint->__construct();
 
    // copy properties to an immutable Point and return it
    $point = new Point($mutablePoint->x, $mutablePoint->y);
    $point->magnitude = $mutablePoint->magnitude;
    return $points[$key] = $point;
}

In reality, this is quite different from how it works in the engine, but this provides a mental model of how behavior should be expected to work.

Performance considerations

To ensure that records are both performant and memory-efficient, the RFC proposes leveraging PHP’s copy-on-write (COW) semantics (similar to arrays) and interning values. Unlike interned strings, the garbage collector will be allowed to clean up these interned records when they’re no longer referenced.

$point1 = &Point(3, 4);
$point2 = $point1; // No data duplication, $point2 references the same data as $point1
$point3 = Point(3, 4); // No data duplication, it is pointing to the same memory as $point1
 
$point4 = $point1->with(x: 5); // Data duplication occurs here, creating a new instance
$point5 = &Point(5, 4); // No data duplication, it is pointing to the same memory as $point4

Cloning and with()

Calling clone on a record results in the same record object being returned. As it is a “value” object, it represents a value and is the same thing as saying clone 3—you expect to get back a 3.

If ->with() is called with no arguments, a warning will be emitted, as this is most likely a mistake.

Serialization and deserialization

Records are fully serializable and deserializable, even when nested.

record Single(string $value);
record Multiple(string $value1, string $value2);
 
echo $single = serialize(&Single('value')); // Outputs: "O:6:"Single":1:{s:5:"value";s:5:"value";}"
echo $multiple = serialize(&Multiple('value1', 'value2')); // Outputs: "O:8:"Multiple":1:{s:6:"values";a:2:{i:0;s:6:"value1";i:1;s:6:"value2";}}"
 
echo unserialize($single) === &Single('value'); // Outputs: true
echo unserialize($multiple) === &Multiple('value1', 'value2'); // Outputs: true

If a record contains objects or values that are unserializable, the record will not be serializable.

Equality

A record is always strongly equal (===) to another record with the same value in the properties, much like an array is strongly equal to another array containing the same elements. For all intents, $recordA === $recordB is the same as $recordA == $recordB.

Comparison operations will behave exactly like they do for classes, which is currently undefined.

Non-trivial values

For non-trivial values (e.g., objects, closures, resources, etc.), the === operator will return true if the two operands reference the same instances.

For example, if two different DateTime records reference the exact same date and are stored in a record, the records will not be considered equal:

$date1 = DateTime('2025-08-04');
$date2 = DateTime('2025-08-04');
 
record Date(DateTime $date);
 
$dateRecord1 = Date($date1);
$dateRecord2 = Date($date2);
 
echo $dateRecord1 === $dateRecord2; // Outputs: false

However, this can be worked around by being a bit creative (see: mental model) as only the values passed in the constructor are compared:

record Date(string $date) {
    public DateTime $datetime;
 
    public function __construct() {
        $this->datetime = new DateTime($this->date);
    }
}
 
$date1 = &Date('2025-08-04');
$date2 = &Date('2025-08-04');
 
echo $date1->datetime === $date2->datetime ? 'true' : 'false'; // Outputs: true

Type hinting

A \Record interface will be added to the engine to allow type hinting for records. All records implement this interface.

function doSomething(\Record $record): void {
    // ...
}

The only method on the interface is with, which is a variadic method that accepts named arguments and returns self.

Reflection

A new reflection class will be added to support records: ReflectionRecord which will inherit from ReflectionClass and add a few additional methods:

  • ReflectionRecord::finalizeRecord(object $instance): Record: Finalizes a record under construction, making it immutable.
  • ReflectionRecord::isRecord(mixed $object): bool: Returns true if the object is a record, and false otherwise.
  • ReflectionRecord::getInlineConstructor(): ReflectionFunction: Returns the inline constructor of the record as ReflectionFunction.
  • ReflectionRecord::getTraditionalConstructor(): ReflectionMethod: Returns the traditional constructor of the record as ReflectionMethod.
  • ReflectionRecord::makeMutable(Record $instance): object: Returns a new record instance with the properties mutable.
  • ReflectionRecord::isMutable(Record $instance): bool: Returns true if the record is mutable, and false otherwise.

Using ReflectionRecord will allow developers to inspect records, their properties, and methods, as well as create new instances for testing or custom deserialization.

Attempting to use ReflectionClass or ReflectionFunction on a record will throw a ReflectionException exception.

finalizeRecord()

The finalizeRecord() method is used to make a record immutable and look up its value in the internal cache, returning an instance that represents the finalized record.

Calling finalizeRecord() on a record that has already been finalized will return the same instance. Attempting to finalize a regular object will throw a ReflectionException.

isRecord()

The isRecord() method is used to determine if an object is a record. It returns true if the object is a finalized record.

getInlineConstructor()

The getInlineConstructor() method is used to get the inline constructor of a record as a ReflectionFunction. This can be used to inspect inlined properties and their types.

Invoking the invoke() method on the ReflectionFunction will create a finalized record.

getTraditionalConstructor()

The getTraditionalConstructor() method is used to get the traditional constructor of a record as a ReflectionMethod. This can be useful to inspect the constructor for further initialization.

Invoking the invoke() method on the ReflectionMethod on a finalized record will throw an exception.

makeMutable()

The makeMutable() method is used to create a new instance of a record with mutable properties. The returned instance doesn’t provide any value semantics and should only be used for testing purposes or when there is no other option.

A mutable record can be finalized again using finalizeRecord(). A mutable record will not be considered a record by isRecord() or implement the \Record interface. It is a regular object with the same properties and methods as the record. For example, var_dump() will output object instead of record.

isMutable()

The isMutable() method is used to determine if a record has been made mutable via makeMutable() or otherwise not yet finalized.

Custom deserialization example

In cases where custom deserialization is required, a developer can use ReflectionRecord to manually construct a new instance of a record.

record Seconds(int $seconds);
 
$example = &Seconds(5);
 
$reflector = new ReflectionRecord(Seconds::class);
$expiration = $reflector->newInstanceWithoutConstructor(); // this is a mutable object
$expiration->seconds = 5;
assert($example !== $expiration); // true
$expiration = $reflector->finalizeRecord($expiration);
assert($example === $expiration); // true

var_dump

When passed an instance of a record the var_dump() function will output the same as if an equivalent object were passed — e.g., both having the same properties — except the output generated will replace the prefix text “object” with the text “record.”

record(Point)#1 (2) {
  ["x"]=>
  int(1)
  ["y"]=>
  int(2)
}

Considerations for implementations

A record cannot share its name with an existing record, class, interface, trait, or function, just like a class.

Autoloading

Records will be autoloaded in the same way as classes.

New Functions

  • record_exists will return true if a record exists and false otherwise. It has the same signature as class_exists.

Backward Incompatible Changes

To avoid conflicts with existing code, the record keyword will be handled similarly to enum to prevent backward compatibility issues.

Since & is currently a syntax error when prefixed on a function call, it will be used to denote a record instantiation.

Proposed PHP Version(s)

PHP 8.5

RFC Impact

To SAPIs

N/A

To Existing Extensions

N/A

To Opcache

Unknown.

New Constants

None

php.ini Defaults

None

Open Issues

Unaffected PHP Functionality

None.

Future Scope

  • Records for “record-like” types, such as DateTime, DateInterval, and others.
  • Short definition syntax for classes

Proposed Voting Choices

2/3 majority.

Patches and Tests

TBD

Implementation

To be completed during a later phase of discussion.

References

Rejected Features

TBD

rfc/records.txt · Last modified: by 127.0.0.1

?
净身出户需要什么条件 自我为中心是什么意思 中元节是什么节日 为什么有的人怎么吃都不胖 女性长期缺维d会带来什么病
胃火旺怎么调理吃什么药最好 脚为什么脱皮 6月23日什么星座 唐字五行属什么 桥本甲状腺炎吃什么药
胃炎糜烂吃什么食物好 梦见自己开车是什么意思 一什么树干 拔完牙后能吃什么 胎菊和金银花一起泡水有什么效果
客串是什么意思 五月七号是什么星座 个人solo什么意思 土豪是什么意思 紫绀是什么症状
什么头什么向hcv9jop1ns5r.cn 梦见狗死了是什么预兆hcv7jop6ns7r.cn 心肌劳损是什么意思hcv9jop1ns0r.cn 朋友开业送什么礼物好hcv8jop3ns0r.cn 血压低头疼是什么原因hcv7jop9ns4r.cn
6月1是什么星座hcv9jop0ns6r.cn 肝火旺盛是什么原因引起的hcv8jop9ns0r.cn 人为什么会打喷嚏hcv9jop0ns7r.cn 老年人打嗝不止是什么原因hcv9jop7ns3r.cn 什么是认知行为疗法hcv7jop5ns4r.cn
小儿风寒感冒吃什么药最好sscsqa.com 梁下放床有什么禁忌hcv9jop2ns8r.cn 高级别上皮内瘤变是什么意思hcv8jop5ns7r.cn 炖牛骨头放什么调料naasee.com prawn是什么意思hcv8jop4ns7r.cn
打不死的小强什么意思hcv9jop7ns9r.cn 牙疼用什么药hcv8jop9ns3r.cn hcg低有什么补救的办法hcv7jop5ns3r.cn 省公安厅厅长是什么级别0735v.com 样本是什么意思hanqikai.com
百度