Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78392 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59056 invoked from network); 27 Oct 2014 15:54:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 15:54:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.174 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.174 mail-ob0-f174.google.com Received: from [209.85.214.174] ([209.85.214.174:52910] helo=mail-ob0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/A0-56216-ABA6E445 for ; Mon, 27 Oct 2014 10:54:35 -0500 Received: by mail-ob0-f174.google.com with SMTP id uz6so3590278obc.19 for ; Mon, 27 Oct 2014 08:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=4NxpdMHAWf9RsM6ytf30cZugDXwOPd1h2yslgK8FH+o=; b=lg5rHh/6kHZO/N6dLh1yhsf5gfRBL5M2yKnFasf34AXzvQMsVR+wtKDC9t9D07Afn1 N2nnhoYul0b7SXkXLZTaWkkQ8LlwhntNxwHJVDUBu2BwG9uy1N3rYsw1QbVtkeEM+Fy2 N/HSUvqTD7YBIoMIowSHtl7FMDNCVII7hKa1Kpa2tji3PYbys0L0WcmCU4n1xEY5Wsz3 iyDYUyx5lVUWvfXoLOTVRAH19UdBPztK2YZnHEmtAba7eirk3L8UxPFY8tRocaUiwtck V8kXT0HbusFRwi7tAXksnkzXE2tEBT35d+RSLPko9rUU6QPsIUE1vocML7ZmVFagio1h P8qw== MIME-Version: 1.0 X-Received: by 10.202.205.82 with SMTP id d79mr2588051oig.67.1414425272089; Mon, 27 Oct 2014 08:54:32 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.76.75.37 with HTTP; Mon, 27 Oct 2014 08:54:32 -0700 (PDT) In-Reply-To: <544DA1CD.9070109@php.net> References: <544DA1CD.9070109@php.net> Date: Mon, 27 Oct 2014 09:54:32 -0600 X-Google-Sender-Auth: n_1K55yxzsQEKTOei2Opz8caJGw Message-ID: To: Stas Malyshev Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: levim@php.net (Levi Morrison) > I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey A few points I have against this proposal, as I understand it: - It does not store the object, only the result of `__hash`. Without the actual object this is not helpful for any use-case I have. - Using a method in the object prevents you from hashing on different members of the objects for different uses. For example, there is a User object. Most of the time the User::id will be used for the hash. However, sometimes the hash needs to be on User::username. If the hashing code is pushed inside the object and call it automatically then you can't hash on the different values. In summary 1) the hashing function should be external to the object, 2) should not be invoked magically, and 3) the object needs to be stored. This can already be done in user-land; here is one such example that I have created but there are others: https://github.com/morrisonlevi/Ardent/blob/master/src/HashMap.php