Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103601 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71771 invoked from network); 13 Dec 2018 17:36:51 -0000 Received: from unknown (HELO mail-it1-f179.google.com) (209.85.166.179) by pb1.pair.com with SMTP; 13 Dec 2018 17:36:51 -0000 Received: by mail-it1-f179.google.com with SMTP id p197so3958260itp.0 for ; Thu, 13 Dec 2018 06:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rC8AhVyGtuQzZZ+y3pfe37xJvG7VgHndYbWmiQpRFdg=; b=jcPjtqWoJfyhXrBQvmZH4jYAOO2OxtfPsTMQbI8b/VgAcYUS3qCwwPtFPiRW/eua0h 7mBehkm9hYJtupdCaaz9eJAoqtaEt8e1TTQOZwqCfeQpvpvO/eRCirG4pALFrzKCSVPl pXD5b2njYSxz9xu14OxfXp2bbTdxUXacJeBD3Uyd6QOg8A3QD8//seBgGGaed6n0ZkFW 8I0gP/8cZIOB+UEFMofMAuAxd9nR5slTKux9V25+WlKziTWyCSQQxeN6sWc/WVJxgALU VzbNPwCI+elW3L6K1du3tyuDqA17qXDY2f0cmRjmAOv7qxf2ZIdAJt8EOYf57wM2+BWz fn9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rC8AhVyGtuQzZZ+y3pfe37xJvG7VgHndYbWmiQpRFdg=; b=cUvfHLXIhQoshrYQ2O5NMqqU5gQhskszJKFfcN8fCXbUn7vY4QSdLsvtnQ1eebSdDl FDhGYeyYntdcCYLzlhKL3GR3JeyG007eaQbvImfiJ2aTq4RkwNCgxT9Q/WZ0Y1fc+CHw tjS3VUCqqJ+zi93c15+RunZ3HsLOHGG3yrBQ0GonW/eyJzXIu43TuXjIQnQZo0pN+BaR XeVbMTFNxnkUFRlGQ94aag8FzMdFMJJ9V4CoK1pSCup+l0zh9rxPAIg/e/6/UWPweJNN 5mdXu18OwuZiFa8xEvA6i+Tu2nH5TQ3eyTcM8x2+7vxRlcWvadzrhSl9jeaypiQ4E/Cn zkhw== X-Gm-Message-State: AA+aEWYGrMNfjdKjxB7akFGxSknF+V2zIwCoYhv9BBwLbFUacM0RA0a/ PgSq8DM1gEGyFcj761aSYMX0lXLY+BFVtMRmNwjF2vFV X-Google-Smtp-Source: AFSGD/VgjrD8smlit/E2GbdFFXhto4jANXhW/ZDvFcWnnfBzVtNQARlMHQKoYbFZplzfSsqeR2oErxhJWJqU/+0VvFs= X-Received: by 2002:a02:3003:: with SMTP id q3mr23424702jaq.16.1544709869408; Thu, 13 Dec 2018 06:04:29 -0800 (PST) MIME-Version: 1.0 Date: Thu, 13 Dec 2018 15:04:17 +0100 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000000c2aec057ce7cb1b" Subject: Typed properties - feature request From: benjamin.morel@gmail.com (Benjamin Morel) --0000000000000c2aec057ce7cb1b Content-Type: text/plain; charset="UTF-8" Hi internals, I have a feature request related to upcoming typed properties, that I'd like to discuss here first. I'm building a data mapper that will target PHP 7.4, and will make heavy use of typed properties. One of the features that I want to have available, is allowing to load a partial object, by giving a list of properties to load: $user = $userRepo->load(123, ['status', 'followerCount']); Under the hood, load() will create a new User object using ReflectionClass:newInstanceWithoutConstructor(), get the data from the database and populate the requested fields using ReflectionProperty::setValue(). Now when I do: $userRepo->save($user); The repo will use the new ReflectionProperty::isInitialized() method to locate which fields are initialized, and only save these to the database. The problem is, newInstanceWithoutConstructor() *initializes properties to their default value*, so save() has no way to know whether initialized properties have been explicitly set during load(), or are just default value (note: repos are stateless). To overcome this problem, I can think of 2 possible options: *Option 1: add an optional parameter to ReflectionClass::newInstanceWithoutConstructor(), to not initialize properties to their default value:* function newInstanceWithoutConstructor(bool $initializeProperties = true) *Option 2: add a ReflectionProperty::unset() method:* function unset(string $property) This way, I could explicitly unset() every property that was not requested during load(). Currently, there is no way to unset() a protected property from outside the object (i.e. in the data mapper). Note that Option 1 would have a slight performance advantage in my case, while Option 2 may have more use cases outside of mine. What do you think? Cheers, Ben --0000000000000c2aec057ce7cb1b--