Re: Introduction & First PHP Extension – Bringing Design by Contract (DbC) to PHP
| From: | Andrea M | Date: | Wed, 19 Mar 2025 21:31:22 +0000 |
| Subject: | Re: Introduction & First PHP Extension – Bringing Design by Contract (DbC) to PHP | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-17680@lists.php.net to get a copy of this message | ||
Thanks for the early feedback.
Yes, that was one of the first things that broke, so I came up with this:
if (invariant_fn) {
zval retval;
zval obj_zval, function_name;
ZVAL_OBJ(&obj_zval, obj);
ZVAL_STRING(&function_name, "__invariant");
// Temporarily restore original zend_execute_ex to prevent infinite
recursion
zend_execute_ex = original_zend_execute_ex;
if (call_user_function(CG(function_table),
&obj_zval,
&function_name,
&retval,
0, NULL) == SUCCESS)
{
zval_ptr_dtor(&retval);
}
// Restore our custom execution hook
zend_execute_ex = invariant_execute_ex;
zval_ptr_dtor(&function_name);
}
I hope this sparks interest.
Best,
Andrea
On Wed, 19 Mar 2025 at 22:24, Yehuda Katz <yehuda@ymkatz.net> wrote:
> This looks really interesting. Does it make sure that there is not a loop
> by calling another class method from inside the invariant check?
>
> - Y
>
> Sent from a device with a very small keyboard and hyperactive autocorrect..
>
> On Wed, Mar 19, 2025, 4:58 PM Andrea M <and.mancuso@googlemail.com> wrote:
>
>> Hi everyone,
>>
>> I started my journey as a LAMP developer back in 2004, working with PHP 4
>> and MySQL 3. For years, PHP was my daily driver, but toward the end of
>> 2011, I transitioned to JavaScript, gradually writing less and less
>> PHP—until it became just an occasional tool in my stack.
>>
>> That changed with *beyond-tabs.com
>> <http://beyond-tabs.com>*. Through
>> this project, I found myself re-embracing PHP, and, thanks to this
>> community, I also discovered *Design by Contract (DbC)*—a paradigm that
>> immediately resonated with me. Now, I want to take the next step and author
>> my very first PHP extension: *Invariant PHP
>> <https://github.com/andreamancuso/invariant-php>*,
>> bringing DbC
>> principles to the language.
>>
>> Beyond just being an extension, I see this as a *proof of concept*—a way
>> to demonstrate the value of DbC in PHP and potentially spark a conversation
>> about native support in future PHP versions. I’m eager to learn from this
>> group, get feedback, and hopefully contribute something meaningful to the
>> ecosystem.
>>
>> Looking forward to your guidance and insights!
>>
>> Best,
>> Andrea
>>
>