Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113429 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33490 invoked from network); 10 Mar 2021 06:17:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2021 06:17:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 732761804B4 for ; Tue, 9 Mar 2021 22:09:43 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 9 Mar 2021 22:09:42 -0800 (PST) Received: by mail-il1-f180.google.com with SMTP id k2so14494536ili.4 for ; Tue, 09 Mar 2021 22:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OqLJwgHqfAG2ba91T47n2/ONlIF97BrRYcznlxy94as=; b=lNyn9KayNXcFHbdtKUxF0ovvvfK/AF2Q7GwwU8GiAtDThmHR4k3PTwrLdK21Ho6Ec/ 4tNiZSJzlV7vqwS9A8rATwzWPsvk2vMG5q2SvxdEYWl+hO49C5WRoQOlaILBFx7w6aC0 cwXLawazDWj5mRMm1ZuCAovgE1PUzcAS7nBpCrseIm8wJEs/pMnTjW9QiA13ZVzCvIl9 o0/rdaZ/uoO1rjdLj+jpwy4rF2b+zjdcbuYjzGparONeB7GvnpvWer2UOppAqlbXWReU 0RjvZzQuz6NMdz2JGF3lIbIZgYxno0e09cXTjkB9Mo0ZORsIQz+7k0e1ZhmMUrNaIelz 6anA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OqLJwgHqfAG2ba91T47n2/ONlIF97BrRYcznlxy94as=; b=nvlOkQMY1urnGhSswm/HM70NuZlEgrjWa/nUETrTCGL1+KMmlCedCuPlgiGmnhklCR M2tuQeUUu7YWcBadGfT5UzUKJ6rMMYt75WDOjfjvJSqXdPhn7Mmq1U/FuKAQyStc3mtz d+NXPwpRutp4AFJY3SjPvShSvQtC3BYJ1OFEt68xN7yPP6wZb1jSGLi85RzwGbRUMQ5G ZG1xcf8Ghhw5VejsCV3ie0TwGc7u30FwG9aoDipAqNeKD9OXlI15vNeVG+O7YCSugfhE jQ16CKakOOwtUDK4EfB7KvtMYSbyWt9eX50gJveKNBxkqCkfie7EVS6uj9CTS8u9Uo7M n5uQ== X-Gm-Message-State: AOAM530TXWVTni3tIJuiGxZC3TNv8T+UfGDPfi+//FVuXLsu9VQhzKiU 8J5y8RlVgHjbyrv18D29nradAwD/j7XKE9maxIE= X-Google-Smtp-Source: ABdhPJyxMAuAzlTWT/8I7bMs5RHlHB2hEUwMlqXpoqJOGRkxqioGEpeOqaF31yNdb2ooWrA7Osw/5Yb7/AeLT1uqqHA= X-Received: by 2002:a05:6e02:1ca2:: with SMTP id x2mr1600777ill.243.1615356581145; Tue, 09 Mar 2021 22:09:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 9 Mar 2021 22:09:30 -0800 Message-ID: To: Michael Wallner Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000034711805bd28834c" Subject: Re: [PHP-DEV] Tracking Object Property Changes From: sutabi@gmail.com (Joseph Montanez) --00000000000034711805bd28834c Content-Type: text/plain; charset="UTF-8" Michael, Thanks for the feedback! The part about having Zend Object at the end of a struct saved me because I was starting to have issues with cloning objects. This is for an extension I was working on and have picked back up, I was just isolating it to make it easy to work with. Its bindings for https://www.raylib.com/. The general issue is that I won't be able to change RayLib's structs (embedded vs pointers), so what I showed was an isolated example. There is another author who also has a RayLib binding in PHP and has a similar issue: https://github.com/oraoto/raylib-phpcpp x += 1; doesn't work $v->x = $v->x + 1; $camera = Camera2D(Vector2(1, 1), Vector2(0, 0), 1.0, 1.0); // $camera->target->x = 1; // doesn't work $target = $camera->target; $target->x = 1; $camera->target = $target; This is far from ideal, and I can only assume people will run into this and assume it's a bug. On my end, I've written my own (incomplete) bindings https://github.com/joseph-montanez/raylib-php | https://joseph-montanez.github.io/raylib-php-docs/ I am working towards those issues, this is just a stumbling block. The more I think about this, I probably don't need a listening system, rather when the object is used for an internal RayLib function call, I can unravel the sub-objects and write back to the original struct. For example in RayLib there is a function DrawRay(Ray ray, Color color), when I implement DrawRay, I can do the unravel work to pull the values from position and direction PHP objects back into the Ray struct, and then pass the Ray struct to DrawRay. Thanks, Joseph Montanez On Tue, Mar 9, 2021 at 3:03 AM Michael Wallner wrote: > Hi Joseph! > > Is this for educational purposes or real world usage? > > I ask, because, if you don't have to adhere to a predefined C-API you > would avoid lots of headache by baking all this stuff into your PHP > objects with the APIs provided by Zend. But then again, it would be way > more efficient to just write it all in PHP code. > > More comments following inline. > > On 09/03/2021 03.32, Joseph Montanez wrote: > > I am not sure what to title this but the gist is that I have two structs > > with a one way dependency: > > > > // Vector3 type > > typedef struct Vector3 { > > float x; > > float y; > > float z; > > } Vector3; > > > > // Ray type (useful for raycast) > > typedef struct Ray { > > Vector3 position; // Ray position (origin) > > Vector3 direction; // Ray direction > > } Ray; > > As these are embedded structs instead of pointers to, neither do point > to the memory of the other. > > > > The PHP Ray object is defined as so: > > typedef struct _skeleton_ray_object { > > Ray ray; > > HashTable *prop_handler; > > zend_object std; > ^^^^^^^^^^^^^^^^ > NOTE: This has to be the last line in your object struct because of an > VLA at the end of the zend_object struct. See your xyz_new() function > where you allocate additional zend_object_properties_size() bytes for > that VLA (variable length array). > > > > > skeleton_vector3_object *position; > > skeleton_vector3_object *direction; > > } skeleton_ray_object; > > > > When I update either vector3 object, I don't have a way to propagate the > > changes back to the parent object(Ray). This means the raw Ray struct is > > never updated. Is there a built-in way to handle propagation (listeners) > in > > a PHP extension or will I need to hand roll this? > > Yes, you gotta write all of this on your own, but let me repeat that > this is a lot of boilerplate which also may entail lots of headache. > > > -- > Regards, > Mike > > --00000000000034711805bd28834c--