[PHP-DEV] [DISCUSSION] C++ Enhancements in Zend API

On Wed, Aug 14, 2024, 11:07 AM Lanre <lnearwaju@gmail.com> wrote:

On Tue, Aug 13, 2024 at 4:28 PM Mike Schinkel <mike@newclarity.net> wrote:

On Aug 12, 2024 at 4:13 PM, <Lanre> wrote:

You’d have to be seriously naive to believe that “the entire industry is actively trying to move AWAY from C/C++.”

Well, there is this:

https://media.defense.gov/2023/Dec/06/2003352724/-1/-1/0/THE-CASE-FOR-MEMORY-SAFE-ROADMAPS-TLP-CLEAR.PDF

-Mike

The source mentions Python and Swift as “memory-safe languages,” both of which are implemented in C and C++. How does that work if C and C++ aren’t memory-safe?

This is the wrong analyze and approach. How many issues happen the past years in the core of a language vs the apps using it would be a better data.

As another example, go is written in go btw.

My argument about using other languages to write extensions or sapi for php is about ease the development and allow more people to do it. FrankenPHP is a very good example. There are others.

Mozilla introduced Rust years ago, yet Firefox remains primarily C++, with only about 3% of the codebase in Rust. By dismissing C and C++, one overlooks the fact that they are crucial for powering everyday systems such as elevators, automotive control units (ECUs, ADAS), medical devices, consumer electronics, industrial automation, and more.

Some of my code running automates on z80 still run. Yet, newer models use mips cpu and C.

Similarly cobol is still used, so are some c cgi applications.

It IS naive to believe that “the entire industry is actively trying to move AWAY from C/C++.”.

you are extrapolating for the sake of it. Every industry has a certain latency to move from one tech to another (or non tech).

It does not prevent new solutions to grow and be used.

also the main topic being how to handle the few cases using c++ dependencies have been elegantly solved already.

On Wed, Aug 14, 2024 at 3:54 AM Pierre Joye <pierre.php@gmail.com> wrote:

On Wed, Aug 14, 2024, 11:07 AM Lanre <lnearwaju@gmail.com> wrote:

On Tue, Aug 13, 2024 at 4:28 PM Mike Schinkel <mike@newclarity.net> wrote:

On Aug 12, 2024 at 4:13 PM, <Lanre> wrote:

You’d have to be seriously naive to believe that “the entire industry is actively trying to move AWAY from C/C++.”

Well, there is this:

https://media.defense.gov/2023/Dec/06/2003352724/-1/-1/0/THE-CASE-FOR-MEMORY-SAFE-ROADMAPS-TLP-CLEAR.PDF

-Mike

The source mentions Python and Swift as “memory-safe languages,” both of which are implemented in C and C++. How does that work if C and C++ aren’t memory-safe?

This is the wrong analyze and approach. How many issues happen the past years in the core of a language vs the apps using it would be a better data.

As another example, go is written in go btw.

My argument about using other languages to write extensions or sapi for php is about ease the development and allow more people to do it. FrankenPHP is a very good example. There are others.

Mozilla introduced Rust years ago, yet Firefox remains primarily C++, with only about 3% of the codebase in Rust. By dismissing C and C++, one overlooks the fact that they are crucial for powering everyday systems such as elevators, automotive control units (ECUs, ADAS), medical devices, consumer electronics, industrial automation, and more.

Some of my code running automates on z80 still run. Yet, newer models use mips cpu and C.

Similarly cobol is still used, so are some c cgi applications.

It IS naive to believe that “the entire industry is actively trying to move AWAY from C/C++.”.

you are extrapolating for the sake of it. Every industry has a certain latency to move from one tech to another (or non tech).

It does not prevent new solutions to grow and be used.

also the main topic being how to handle the few cases using c++ dependencies have been elegantly solved already.

This conversation is a waste of both of our times, have a wonderful day, cheers.

On 11 August 2024 23:52:00 BST, Lanre <lnearwaju@gmail.com> wrote:

I’m considering adding some C++ enhancements to the Zend API. These changes
would be encapsulated within `#ifdef __cplusplus` guards, so they wouldn’t
interfere with the existing C implementation. The primary goal is to
provide a nicer interface for extensions while maintaining compatibility
with C.

Hi Lanre,

This thread seems to have become quite heated, perhaps because people tend to have strong opinions about different programming languages.

It might help reset the discussion to draft a quick RFC outlining what is being proposed, and why.

I think some key things that would need to be considered are:

1. Why does this belong in the core repository, vs a separate library such as PHP-CPP? Would it be easier to have it maintained by people familiar with the core engine, but not with C++, rather than people outside the project, but familiar with C++? Are there technical reasons why some features require / benefit from being part of the same files / directories as the C API? Are there potential uses for things which are already in the core, such as bundled extensions?

2. Does this imply the PHP project "blessing" C++ in some way, over other languages? Or does it imply we could/should have similar wrappers for other languages, such as Rust and Go? (Ignoring any personal views, both are in active use in similar contexts, and a quick search turned up ext_php_rs - Rust and GitHub - deuill/go-php: PHP bindings for the Go programming language (Golang))

3. What guarantees can/should we provide about the stability and maintenance of these additional API elements? Note that this crosses over with point 1 - a separate library can make breaking changes on a different cycle to the core project, and even add C++ (or Rust, Go, etc) APIs for already released versions of the engine.

Regards,
Rowan Tommins
[IMSoP]

On Wed, Aug 14, 2024 at 4:30 AM Pascal Chevrel <pascalc@gmail.com> wrote:

Le 14/08/2024 à 05:03, Lanre a écrit :

Mozilla introduced Rust years ago, yet Firefox remains primarily C++,
with only about 3% of the codebase in Rust.

Hi,

10.3% now https://openhub.net/p/firefox/analyses/latest/languages_summary

Firefox is 31 million lines of code, that means 3.4 million lines of
code written in Rust.

Rewriting everything in Rust has never been a goal but Rust is usually
favored over C++ for new projects or rewrites. I don’t think you can
take Mozilla as an example (pro or con) in the context of PHP as the
contexts and constraints are way different.

Regards

Pascal

So how is Rust relevant to this conversation? PHP is implemented in C AND C++ already, except it has shitty C++ support. I bring that up and propose improving it and what am i met with? Stupid questions about rust with stupid reasons for not wanting this in core. I mean look at this shit:

  • If it’s so easy and transparent to improve support for C++, it could easily exist outside of core as a set of header files to make the lift lighter for someone looking to use it. Sounds like that project already exists (no idea, didn’t look into it).

  • Even if it’s “easy” with a few header files, it’s still adding a whole new thing required to maintain the project because now someone has to own and maintain a C++ API and every change to the “real” C engine needs a corresponding C++ API update. Who here long-term is going to own that engine-level API and make sure it’s “the C++ way”…you? The way you’re behaving I wouldn’t trust you to not rage-quit today… so who then? What happens if there is a conflict between “the C way” and “the C++ way” in regards to a new engine-level API down the road? What kind of extra thought / energy / consideration do we need to put into engine-level API changes in the future because now we have to maintain two distinct engine APIs?

  • If it’s not so easy and transparent (e.g. requiring us to start modifying the engine because C++ isn’t happy), I’m opposed to the idea because conceptually I’d like to see any such effort spent on improving support for a future-looking language. I honestly don’t care what that is, but considering Linux’s recent embracing of Rust I think that’s got some merit to consider. For the record, I don’t personally even code in Rust so attacking me like I’ve got a horse in that race is pretty ridiculous.

  • I don’t believe that just because something is prevalent means it’s good. Entire governments are starting to recommend not using C/C++ because of the security risks posed by its non-existent memory safety. If PHP was being written today, it wouldn’t have been written in C.

Clearly this guy has no clue what he’s talking about, yet I’m supposed to convince people like him? His suggestions range from “leave it to a third party lib” to “i don’t trust you to not rage-quit”. I’m not asking for anything extreme—just to improve the API. Yet, I’m being told that C++ is obsolete because of Rust. That’s why I mentioned that Firefox is still primarily written in C++, even though they’ve introduced Rust. I’m not expecting a full Rust rewrite from them (which would be both unwise and wasteful); I just want to highlight how unreasonable it is to suggest that improving C++ support in the engine is pointless.

Cheers,
Lanre.

I want to remind everyone on the thread that code does not only have to be written, which is the “easy part”, but it also has to be supported by everyone into the future and chances that the original author sticks around are not that high to do it.

The Rust thing is shitposting for the sake of shitposting and memeing on the theme “rust solves everything” and “lets rewrite everything into Rust”.
Here’s a link with the reminder of the hard rules php-src and internals have: https://github.com/php/php-src/blob/master/docs/mailinglist-rules.md

And here’s the wiki page on the internals etiquette: https://wiki.php.net/email_etiquette_for_people_new_to_php_internals

PHP has C as core and has allowed C++ for extensions. Expanding that support is a no-brainer, especially since modern C++ has stepped up in major ways and I don’t think C sees a lot of development any more, so it makes sense to move towards C++.
The only thing people on this thread need to agree on is the timeline for expanding that support. I would suggest adopting a multi-year schedule through multiple PHP versions and get that show on the road.

···

Arvīds Godjuks+371 26 851 664
arvids.godjuks@gmail.com
Telegram: @psihius https://t.me/psihius

On Aug 14, 2024, at 3:05 PM, Arvids Godjuks <arvids.godjuks@gmail.com> wrote:

I want to remind everyone on the thread that code does not only have to be written, which is the "easy part", but it also has to be supported by everyone into the future and chances that the original author sticks around are not that high to do it.

The Rust thing is shitposting for the sake of shitposting and memeing on the theme "rust solves everything" and "lets rewrite everything into Rust".
Here's a link with the reminder of the hard rules php-src and internals have: php-src/docs/mailinglist-rules.md at master · php/php-src · GitHub
And here's the wiki page on the internals etiquette: PHP: email_etiquette_for_people_new_to_php_internals

PHP has C as core and has allowed C++ for extensions. Expanding that support is a no-brainer, especially since modern C++ has stepped up in major ways and I don't think C sees a lot of development any more, so it makes sense to move towards C++.

IF there is a serious consideration given to evolving PHP to be written in another language — vs. just a newer version of C — I think any reasonable analysis would indicate that none of the languages proposed in this thread would be appropriate; not Rust, not C++, and not Go. Why not?

1. Rust is vastly different from C and re-writing in Rust would require basically rewriting everything from ground up. The scope of such as project would likely make the failed effort toward PHP6 even look quaint.

Yes, it is possible that one or a few individuals could on-their-own devote 1-3 years to write PHP in Rust and then present to the community and the community could accept it as the next version of PHP. However, AFAIK there is no one individual or team who is currently or likely to do this, and having the community accept their work is even less likely.

2. C++ is vastly more complicated to program in than C, and adopting C++ would further narrow the number of people who are both proficient enough in both C++ and motivated enough to contribute to PHP's codebase. That would likely be just a handful of people today and with not much prospect for more in the future.

3. While I would love it if PHP were written in Go, I just do not see it happening because it would take a mostly full rewrite like with Rust and even as a Gopher I am not sure Go is the language I would pick to develop PHP in if there were no existing constrains in large part because of its inability to go low-level enough (pun intended), especially related to memory management.

However, there *IS* a language I think the PHP should seriously consider — if we do seriously consider a new language at all— and that language is Zig.

If you are not familiar with Zig — or have simply not explored it yet — I would highly recommend reading at least the first article if not all of them:

https://www.infoworld.com/article/2338081/meet-the-zig-programming-language.html
Why Zig When There is Already C++, D, and Rust? ⚡ Zig Programming Language
Is Zig the Long Awaited C Replacement? | by Erik Engheim | Medium
Revisiting the design approach to the Zig programming language

For those who can't be bothered to visit any of the links but will read the rest of an email, here are pull quotes from the first article that are relevant to why Zig should be considered as a successor to C for PHP. I presented these quotes in order of relevance for PHP and not in order presented in the article:

— "Zig sports a high degree of interoperability with C and C++. ... Zig can compile C and C++. It also ships with libc libraries for many platforms. It is able to build these without linking to external libc libraries."

— "Zig attempts not only to supercede C with its own syntax, but actually absorb C into itself as much as possible."

— "(Zig's developer) said “Zig is a better C/C++ compiler than other C/C++ compilers since it supports cross-compilation out of the box, among other things. Zig can also trivially interoperate with C (you can import C header files directly) and it is overall better than C at using C libraries, thanks to a stronger type system and language features like defer.”

— "There is no malloc keyword like in C and C++. Instead, access to the heap is handled explicitly in the standard library. When you need such a feature, you pass in an Allocator object. This has the effect of clearly denoting when memory is being engaged by libraries while abstracting how it should be addressed. Instead, your client code determines what kind of allocator is appropriate."

— "Making memory access an obvious library characteristic is meant to avoid hidden allocations, which is a boon to resource-limited and real-time environments. Memory is lifted out of the language syntax, where it can appear anywhere, and its handling is made more explicit."

— "Zig also includes safety features for avoiding buffer overflows, and it ships with a debug allocator that detects memory leaks."

— "Zig also includes a build tool.... Zig’s build tool works in a cross-platform way and replaces tools like make and cmake."

— "Zig is being used to implement the Bun.js JavaScript runtime as an alternative to Node.js. Bun’s creator Jarred Sumner told me “Zig is sort of similar to writing C, but with better memory safety features in debug mode and modern features like defer (sort of similar to Go’s) and arbitrary code can be executed at compile time via comptime. It has very few keywords so it’s a lot easier to learn than C++ or Rust.”

— "Kevin Lynagh, coming from a Rust background, wrote, “The language is so small and consistent that after a few hours of study I was able to load enough of it into my head to just do my work.” Nathan Craddock, a C developer, echoed the sentiment. Programmers seem to really like the focused quality of Zig’s syntax."

============

Given that Zig was designed to and can compile C and C++ code directly, "moving to" Zig would likely be almost trivial, at least the swapping out the C compiler for the Zig compiler part. Then the maintainers of PHP could decide which Zig languages features to use and where. Over time PHP's maintainers could choose to evolve the PHP codebase to using more Zig features over time (or not), features such as `comptime` code generation that is built into the Zig language.

Zig's allocator memory model would also likely be a boon to PHP by giving PHP more control about how and when to allocate memory for PHP programs.

Using the Zig build tool could also likely make it easier for someone new to PHP core/extension development to getting a build working on their machine for local development.

And finally, one other (IMO) HUGE benefit of switching to Zig would be that it would likely be easier for new people to onboard to contributing to the PHP codebase than if PHP sticks with C or especially if PHP were to instead move to C++. I know Zig would make it easier for me to contribute.

#jmtcw

-Mike

P.S. One of my goals in the mid-term is to become proficient enough to work in C on the PHP code base so I could write an extension and/or contribute a patch to PHP for a passed RFC.

However, if PHP embraces C++ I will drop that goal because I know enough about C++ to know about that I to become proficient in contributing to PHP if it required be programming in C++ would need to become a full time C++ developer, which is not going to happen. So if you move to C++ then I give up.

That said, me giving up will be no skin off anyone's nose in the PHP community. But it is very likely my giving up would just be the canary dying in the coal mine indicating that many others will give up too, and many more will never even try.

IOW, if you care about being able to have enough people to maintain PHP into the future, you should really think hard before deciding to more PHP to C++ development. And before you say there are lots of C++ developers, consider that most good C++ would never even consider working on PHP as they likely do not consider it a language worthy of their time.

On Wed, Aug 14, 2024 at 2:32 PM Mike Schinkel <mike@newclarity.net> wrote:

On Aug 14, 2024, at 3:05 PM, Arvids Godjuks <arvids.godjuks@gmail.com> wrote:

I want to remind everyone on the thread that code does not only have to be written, which is the “easy part”, but it also has to be supported by everyone into the future and chances that the original author sticks around are not that high to do it.

The Rust thing is shitposting for the sake of shitposting and memeing on the theme “rust solves everything” and “lets rewrite everything into Rust”.
Here’s a link with the reminder of the hard rules php-src and internals have: https://github.com/php/php-src/blob/master/docs/mailinglist-rules.md
And here’s the wiki page on the internals etiquette: https://wiki.php.net/email_etiquette_for_people_new_to_php_internals

PHP has C as core and has allowed C++ for extensions. Expanding that support is a no-brainer, especially since modern C++ has stepped up in major ways and I don’t think C sees a lot of development any more, so it makes sense to move towards C++.

IF there is a serious consideration given to evolving PHP to be written in another language — vs. just a newer version of C — I think any reasonable analysis would indicate that none of the languages proposed in this thread would be appropriate; not Rust, not C++, and not Go. Why not?

Can you point out where either of us suggested writing PHP in another language? You might be mixing this up with the C11 thread, which has nothing to do with this. All I’m proposing is improving the current C++ support in the engine. https://github.com/php/php-src/blob/master/Zend/zend_portability.h already guarantees compatibility with c++ thanks to the BEGIN_EXTERN_C() and END_EXTERN_C() macros defined right at the top and that are used all around the engine. Notice how that macro compiles to nothing when C++ isn’t being used? I’m simply proposing more of those.

  1. Rust is vastly different from C and re-writing in Rust would require basically rewriting everything from ground up. The scope of such as project would likely make the failed effort toward PHP6 even look quaint.

Yes, it is possible that one or a few individuals could on-their-own devote 1-3 years to write PHP in Rust and then present to the community and the community could accept it as the next version of PHP. However, AFAIK there is no one individual or team who is currently or likely to do this, and having the community accept their work is even less likely.

  1. C++ is vastly more complicated to program in than C, and adopting C++ would further narrow the number of people who are both proficient enough in both C++ and motivated enough to contribute to PHP’s codebase. That would likely be just a handful of people today and with not much prospect for more in the future.

  2. While I would love it if PHP were written in Go, I just do not see it happening because it would take a mostly full rewrite like with Rust and even as a Gopher I am not sure Go is the language I would pick to develop PHP in if there were no existing constrains in large part because of its inability to go low-level enough (pun intended), especially related to memory management.

However, there IS a language I think the PHP should seriously consider — if we do seriously consider a new language at all— and that language is Zig.

If you are not familiar with Zig — or have simply not explored it yet — I would highly recommend reading at least the first article if not all of them:

https://www.infoworld.com/article/2338081/meet-the-zig-programming-language.html
https://ziglang.org/learn/why_zig_rust_d_cpp/
https://erik-engheim.medium.com/is-zig-the-long-awaited-c-replacement-c8eeace1e692
https://sourcegraph.com/blog/zig-programming-language-revisiting-design-approach

For those who can’t be bothered to visit any of the links but will read the rest of an email, here are pull quotes from the first article that are relevant to why Zig should be considered as a successor to C for PHP. I presented these quotes in order of relevance for PHP and not in order presented in the article:

— “Zig sports a high degree of interoperability with C and C++. … Zig can compile C and C++. It also ships with libc libraries for many platforms. It is able to build these without linking to external libc libraries.”

— “Zig attempts not only to supercede C with its own syntax, but actually absorb C into itself as much as possible.”

— "(Zig’s developer) said “Zig is a better C/C++ compiler than other C/C++ compilers since it supports cross-compilation out of the box, among other things. Zig can also trivially interoperate with C (you can import C header files directly) and it is overall better than C at using C libraries, thanks to a stronger type system and language features like defer.”

— “There is no malloc keyword like in C and C++. Instead, access to the heap is handled explicitly in the standard library. When you need such a feature, you pass in an Allocator object. This has the effect of clearly denoting when memory is being engaged by libraries while abstracting how it should be addressed. Instead, your client code determines what kind of allocator is appropriate.”

— “Making memory access an obvious library characteristic is meant to avoid hidden allocations, which is a boon to resource-limited and real-time environments. Memory is lifted out of the language syntax, where it can appear anywhere, and its handling is made more explicit.”

— “Zig also includes safety features for avoiding buffer overflows, and it ships with a debug allocator that detects memory leaks.”

— “Zig also includes a build tool… Zig’s build tool works in a cross-platform way and replaces tools like make and cmake.”

— "Zig is being used to implement the Bun.js JavaScript runtime as an alternative to Node.js. Bun’s creator Jarred Sumner told me “Zig is sort of similar to writing C, but with better memory safety features in debug mode and modern features like defer (sort of similar to Go’s) and arbitrary code can be executed at compile time via comptime. It has very few keywords so it’s a lot easier to learn than C++ or Rust.”

— “Kevin Lynagh, coming from a Rust background, wrote, “The language is so small and consistent that after a few hours of study I was able to load enough of it into my head to just do my work.” Nathan Craddock, a C developer, echoed the sentiment. Programmers seem to really like the focused quality of Zig’s syntax.”

============

Given that Zig was designed to and can compile C and C++ code directly, “moving to” Zig would likely be almost trivial, at least the swapping out the C compiler for the Zig compiler part. Then the maintainers of PHP could decide which Zig languages features to use and where. Over time PHP’s maintainers could choose to evolve the PHP codebase to using more Zig features over time (or not), features such as comptime code generation that is built into the Zig language.

Zig’s allocator memory model would also likely be a boon to PHP by giving PHP more control about how and when to allocate memory for PHP programs.

Using the Zig build tool could also likely make it easier for someone new to PHP core/extension development to getting a build working on their machine for local development.

All of this is moot, it would be a huge investment and a whole other discussion to port PHP to another language. That has nothing to do with my proposal.

And finally, one other (IMO) HUGE benefit of switching to Zig would be that it would likely be easier for new people to onboard to contributing to the PHP codebase than if PHP sticks with C or especially if PHP were to instead move to C++. I know Zig would make it easier for me to contribute.

#jmtcw

-Mike

P.S. One of my goals in the mid-term is to become proficient enough to work in C on the PHP code base so I could write an extension and/or contribute a patch to PHP for a passed RFC.

However, if PHP embraces C++ I will drop that goal because I know enough about C++ to know about that I to become proficient in contributing to PHP if it required be programming in C++ would need to become a full time C++ developer, which is not going to happen. So if you move to C++ then I give up.

Again, I will reiterate that these proposed changes will not affect the current course of PHP. Development will go on as usual and any bugs introduced by this proposal will be contained to C++ extensions interacting with the code. C devs can act like this doesn’t even exist because as far as the C compiler is concerned, it doesn’t. On the other hand C++ devs won’t have to keep reinventing the wheel whenever they have to build an extension with C++. What is a php extension if not a wrapper for a C/C++ lib?

That said, me giving up will be no skin off anyone’s nose in the PHP community. But it is very likely my giving up would just be the canary dying in the coal mine indicating that many others will give up too, and many more will never even try.

IOW, if you care about being able to have enough people to maintain PHP into the future, you should really think hard before deciding to more PHP to C++ development. And before you say there are lots of C++ developers, consider that most good C++ would never even consider working on PHP as they likely do not consider it a language worthy of their time.

IF I wanted PHP to be implemented in C++, I would simply fork it. How many thousand RFCs do you think it will take to get anything reasonable done? I’m baffled that I actually have to convince y’all to IMPROVE the current support for C++, but calm down, no one wants you to quit.

Cheers,
Lanre.

On Aug 14, 2024, at 5:27 PM, Lanre <lnearwaju@gmail.com> wrote:

On Wed, Aug 14, 2024 at 2:32 PM Mike Schinkel <mike@newclarity.net> wrote:
> On Aug 14, 2024, at 3:05 PM, Arvids Godjuks <arvids.godjuks@gmail.com> wrote:
> PHP has C as core and has allowed C++ for extensions. Expanding that support is a no-brainer, especially since modern C++ has stepped up in major ways and I don't think C sees a lot of development any more, so it makes sense to move towards C++.

IF there is a serious consideration given to evolving PHP to be written in another language — vs. just a newer version of C — I think any reasonable analysis would indicate that none of the languages proposed in this thread would be appropriate; not Rust, not C++, and not Go. Why not?

Can you point out where either of us suggested writing PHP in another language?

Arvids wrote "I don't think C sees a lot of development any more, so it makes sense to move towards C++."

That statement was why I wrote my email.

You might be mixing this up with the C11 thread, which has nothing to do with this.

No, not the case.

All I'm proposing is improving the current C++ support in the engine.

I was not replying to your email(s). I was replying to Arvids' email which was worded as if moving to C++ for PHP was a foregone conclusion.

php-src/Zend/zend_portability.h at master · php/php-src · GitHub already guarantees compatibility with c++ thanks to the BEGIN_EXTERN_C() and END_EXTERN_C() macros defined right at the top and that are used all around the engine. Notice how that macro compiles to nothing when C++ isn't being used? I'm simply proposing more of those.

I made no comment pro nor con regarding that proposal.

All of this is moot, it would be a huge investment and a whole other discussion to port PHP to another language. That has nothing to do with my proposal.

I could be wrong as I am not an expert in either C or Zig, but from what I understand from others who have adopted Zig for C code bases it would not be a huge investment at all. Which is why I proposed it.

Again, I will reiterate that these proposed changes will not affect the current course of PHP. Development will go on as usual and any bugs introduced by this proposal will be contained to C++ extensions interacting with the code. C devs can act like this doesn't even exist because as far as the C compiler is concerned, it doesn't. On the other hand C++ devs won't have to keep reinventing the wheel whenever they have to build an extension with C++. What is a php extension if not a wrapper for a C/C++ lib?

IF I wanted PHP to be implemented in C++, I would simply fork it. How many thousand RFCs do you think it will take to get anything reasonable done? I'm baffled that I actually have to convince y'all to IMPROVE the current support for C++, but calm down, no one wants you to quit.

Again, I did not comment on your proposal pro nor con.

OTOH, as others discussed moving to Rust or C++ I wanted to ensure a more compelling alternative — Zig — was at least mentioned and considered, assuming a change is being/will be considered at all.

-Mike

P.S. BTW, didn't you already say this conversation was a waste of your time and imply that you were done with the thread? Then why would I be replying to you?

Arvids wrote “I don’t think C sees a lot of development any more, so it makes sense to move towards C++.”

Yeah he wrote that right after “PHP has C as core and has allowed C++ for extensions. Expanding that support is a no-brainer, especially since modern C++ has stepped up in major ways”. That is also known as context.

I could be wrong as I am not an expert in either C or Zig, but from what I understand from others who have adopted Zig for C code bases it would not be a huge investment at all. Which is why I proposed it.

Well the source code is right there, go ahead and explore adopting Zig and feel free to report back with your findings. Until then, I think we should stick to something that has been battle tested over the past 30 years.

Again, I will reiterate that these proposed changes will not affect the current course of PHP. Development will go on as usual and any bugs introduced by this proposal will be contained to C++ extensions interacting with the code. C devs can act like this doesn’t even exist because as far as the C compiler is concerned, it doesn’t. On the other hand C++ devs won’t have to keep reinventing the wheel whenever they have to build an extension with C++. What is a php extension if not a wrapper for a C/C++ lib?

IF I wanted PHP to be implemented in C++, I would simply fork it. How many thousand RFCs do you think it will take to get anything reasonable done? I’m baffled that I actually have to convince y’all to IMPROVE the current support for C++, but calm down, no one wants you to quit.

Again, I did not comment on your proposal pro nor con.

Fair enough.

P.S. BTW, didn’t you already say this conversation was a waste of your time and imply that you were done with the thread? Then why would I be replying to you?

Nah, I meant the specific conversation with Pierre Joye, it wasn’t going anywhere. I stand by all my points so why would I just leave because of some confused folks?

Cheers,
Lanre.

On Thu, Aug 15, 2024, 6:35 AM Lanre <lnearwaju@gmail.com> wrote:

Arvids wrote “I don’t think C sees a lot of development any more, so it makes sense to move towards C++.”

Nah, I meant the specific conversation with Pierre Joye, it wasn’t going anywhere. I stand by all my points so why would I just leave because of some confused folks?

it ends on the clarification about being related to ease extension support for c++.

I also have to reitere my earlier suggestion. Please stop telling others here they have no clue, are clueless, ignorant or what else.

it is ok to disagree, even strongly. This tone however is not ok, at all.

thanks for your understanding.

Pierre

On Aug 14 2024, at 5:27 pm, Lanre lnearwaju@gmail.com wrote:

Can you point out where either of us suggested writing PHP in another language? You might be mixing this up with the C11 thread, which has nothing to do with this. All I’m proposing is improving the current C++ support in the engine. https://github.com/php/php-src/blob/master/Zend/zend_portability.h already guarantees compatibility with c++ thanks to the BEGIN_EXTERN_C() and END_EXTERN_C() macros defined right at the top and that are used all around the engine. Notice how that macro compiles to nothing when C++ isn’t being used? I’m simply proposing more of those.

You aren’t simply “proposing more of those [macros]”. Per your original email:

Key points:

  • Struct-based Approach: Everything will still use structs—no classes or non-public/non-static members.
  • Isolation: Any enhancements that can be isolated from the C implementation will be, and they will reside in a common zend_api_cxx header file.
  • Proposed Enhancements:
  • Constructors and destructors, along with comparison operator overloads for zval.
  • Constructor overloads for common zval initializations.
  • Member methods for common zval operations.

You have been asked three times now by two different people to put together an RFC of exactly what you are proposing. You have also been asked by multiple people multiple times to stop hurling insults at people you disagree with. If you can’t or won’t do these things, then I don’t see the point in continuing this thread.

On Thu, Aug 15, 2024 at 8:51 AM John Coggeshall <john@coggeshall.org> wrote:

On Aug 14 2024, at 5:27 pm, Lanre <lnearwaju@gmail.com> wrote:

Can you point out where either of us suggested writing PHP in another language? You might be mixing this up with the C11 thread, which has nothing to do with this. All I’m proposing is improving the current C++ support in the engine. https://github.com/php/php-src/blob/master/Zend/zend_portability.h already guarantees compatibility with c++ thanks to the BEGIN_EXTERN_C() and END_EXTERN_C() macros defined right at the top and that are used all around the engine. Notice how that macro compiles to nothing when C++ isn’t being used? I’m simply proposing more of those.

You aren’t simply “proposing more of those [macros]”. Per your original email:

Key points:

  • Struct-based Approach: Everything will still use structs—no classes or non-public/non-static members.
  • Isolation: Any enhancements that can be isolated from the C implementation will be, and they will reside in a common zend_api_cxx header file.
  • Proposed Enhancements:
  • Constructors and destructors, along with comparison operator overloads for zval.
  • Constructor overloads for common zval initializations.
  • Member methods for common zval operations.

You have been asked three times now by two different people to put together an RFC of exactly what you are proposing. You have also been asked by multiple people multiple times to stop hurling insults at people you disagree with. If you can’t or won’t do these things, then I don’t see the point in continuing this thread.

You’re embarrassing yourself John, read my very first paragraph (you got this). I will make an RFC when i get the chance. Also I’m sorry for ‘bullying’ you but you should learn to stay out of stuff that doesn’t concern you. You don’t know a lick of C++, you never write it, so you can’t speak on the benefits of this, it is a non intrusive change that won’t affect C, yet you’re against it for some stupid reasons. Sorry for hurting your feelings, that was not my intention. Have a wonderful day John.

Cheers,
Lanre.

On 15 August 2024 18:10:11 BST, Lanre <lnearwaju@gmail.com> wrote:

You're embarrassing yourself John, read my very first paragraph (you got this).

We have said this before, but you *really* need to stop using condescending language, and ad-hominems like this.

cheers
Derick

On Thu, Aug 15, 2024 at 11:33 AM Derick Rethans <derick@php.net> wrote:

On 15 August 2024 18:10:11 BST, Lanre <lnearwaju@gmail.com> wrote:

You’re embarrassing yourself John, read my very first paragraph (you got this).

We have said this before, but you really need to stop using condescending language, and ad-hominems like this.

cheers
Derick

Then maybe he should stop embarrassing himself. How many times do you want me to repeat myself? How did he miss my introductory paragraph, while quoting that same email, to ask me a question that is answered in that paragraph? That isn’t considered an attack? But calling that embarrassing is? My bad.

Lanre.

On Thu, Aug 15, 2024 at 11:42 AM Lanre <lnearwaju@gmail.com> wrote:

On Thu, Aug 15, 2024 at 11:33 AM Derick Rethans <derick@php.net> wrote:

On 15 August 2024 18:10:11 BST, Lanre <lnearwaju@gmail.com> wrote:

You’re embarrassing yourself John, read my very first paragraph (you got this).

We have said this before, but you really need to stop using condescending language, and ad-hominems like this.

cheers
Derick

Then maybe he should stop embarrassing himself. How many times do you want me to repeat myself? How did he miss my introductory paragraph, while quoting that same email, to ask me a question that is answered in that paragraph? That isn’t considered an attack? But calling that embarrassing is? My bad.

Lanre.

Isn’t rule 4 of the organizational rules section of the mailing list rules “Make sure you know what you are talking about.”? Why am I the only person being reminded of the rules?

On Thu, 15 Aug 2024, 18:50 Lanre, <lnearwaju@gmail.com> wrote:

Why am I the only person being reminded of the rules?

Maybe because during the aggregate time you’ve spent slandering your fellow man, you could have written that RFC you claim to not have had the time to write.

On Thu, Aug 15, 2024 at 11:53 AM Bilge <bilge@scriptfusion.com> wrote:

On Thu, 15 Aug 2024, 18:50 Lanre, <lnearwaju@gmail.com> wrote:

Why am I the only person being reminded of the rules?

Maybe because during the aggregate time you’ve spent slandering your fellow man, you could have written that RFC you claim to not have had the time to write.

Lol I would have to ask for RFC karma first, then when I get that I have to write a whole document, just to make the same points I spent three days making here with little success. Believe it or not, I have better things to do with my time. I’m currently in the process of drafting it and I will get to it when I get the chance.

Cheers,
Lanre.

John reached out to me directly, but i think he raised some valid points that I should address here, so here it is:

On Thu, Aug 15, 2024 at 1:56 PM John Coggeshall <john@coggeshall.org> wrote:

Lanre,

I think you’re expectations are probably unrealistic if you expected to drop a PR in a week to add C++ support as you describe, and expect it to be immediately accepted (which is what I’m taking from your “I had a week off to do this” comment).

Correct me if i’m wrong but aren’t RFCs usually for changes that somehow affect userland or the API? This does neither and is fairly simple to implement so I assumed this thread would be more about implementation details and what branch to merge this to. It isn’t unrealistic for me, but to each their own.

Also, I honestly couldn’t care less how much money you make – it doesn’t excuse your behavior on the list.

Never said it did, just letting you know the caliber of C++ dev I am,and that I am much more familiar with C++ than you are. I get paid a lot to do what I’m offering to do for free.

I shouldn’t have to privately message you in order for you to act with some decorum in the Internals list – it won’t be me that does it, but I am certain if you don’t knock it off you’ll just be removed eventually if you keep it up. That’s not a threat, it’s just what eventually happens.

You most certainly did not have to message me privately.

But let’s get back to the merits of what you are talking about. To be entirely honest I really don’t have the time to walk through all of it with you, but I’ll do my best to give you some insights that will help you be successful in at least pitching your ideas to the community.

First you have to understand that, generally speaking, there isn’t a ton of appetite to spend a lot of energy on C++ for internals… That’s largely a historic issue, as I’d bet most of us are C devs first and PHP for better or worse was written in C. That’s not to say you’re idea isn’t worth considering – but it does mean you’re going to face a bit of an uphill battle.

Which is pretty ridiculous. I am not asking for anything too crazy and I shouldn’t have to face an uphill battle when all I’m doing is maintenance. Why does it have to be personal?

I’m not entirely clear what you mean when you say handling this at the extension level is “breaking portability” – in what sense do you mean? I’m also a little confused by your statement “these new subclasses in each extension”… subclasses of what parent class?

zval parent class.

Either way, anytime people start talking about messing around with zval, you’re going to get a lot of questions for obvious reasons. If you are serious about this there are a few things you need to consider:

Which is why Ii’m not messing around with zval. Yes there will be a constructor and destructor, comparison operators as well as common methods, which will all be behind a C++ macro. Those are necessary changes

  • It matters to this project, and every open source project, that there is a confidence that people will be around to maintain stuff other people built. If you are the only person who is able to maintain something you’ve put into core that’s a big problem. I don’t expect anyone to maintain their code forever here, nor should you assume they will. I have a nearly never-ending list of code across multiple open source projects where someone showed up, wrote some code no one else could maintain for whatever reason, and 6 mos later disappeared leaving the project holding the bag. It’s not that I don’t think you understand code requires maintenance – it’s that you don’t seem to understand eventually you’re going to probably move on and leave and someone else is going to maintain your code… or worse, your code goes unmaintained and the whole project suffers.

What are you basing this on? You just read my proposal and instead of attacking the points I made, you are making baseless accusations. I don’t get paid for this, so obviously I will only maintain it for as long as it interests me, which is completely fair. PHP Foundation exists and accepts donations for what exactly if not to pay devs to maintain php-src?

  • One of the ways to get past the issue above is to create confidence around your idea that there is enough talent in the community to maintain your code without you by clearly explaining in detail exactly what the work is, why its important, and showing you’ve put the thought into long-term maint of the changes as necessary. To wit;

Why do you assume that no one else is capable of maintaining this?

  • I have a lot of questions about what your suggested implementation (I assume basically you are suggesting your “Option A” becomes part of core – or something similar?) would mean for the codebase as a whole. Many of these concerns stem from my first point above. Here are just two of them that seem relevant immediately:
    • Is this literally a wrapper around zval (allocated separately), or are you proposing we start allocating zval s on an object creation?

Yes, when implemented as an extension, it has to be a subclass of zval. If implemented in core though, it would be added directly to zval (under C++ guards).

    • If we now have an object that represents a zval , does that mean this object has methods that reflect the C function calls? e.g. is there a print method that maps to zend_print_zval ?

C doesn’t have methods. And maybe? That’s part of the implementation details I was hoping do discuss.

    • If you are now introducing a whole new way to “print a zval” (e.g. zend_print_zval(myZval) and myZval->print() , what is the justification for a whole new API?

A print method would fall under ‘common methods’ not a big deal, but it would improve readability in C++ code.

      • Who is going to maintain it? Right now we already have to worry about API changes just dealing with the C level stuff… now we’ve doubled the problem because of C++ stuff if it also has a method-based API.

Me, until I get bored, then hopefully someone else. Is there a different way it’s supposed to go?

      • There won’t always been a clear translation of zend_print_eval to print() , isn’t introducing a new OO API on top of the procedural one going to butt heads on some points? Who wins?

How would it butt heads if it doesn’t even work in C? Who would be butting heads exactly? I think i’m missing your point here.

      • What about the values inside of zval , do you propose proxying access to those from this class? (e.g. myZval->v )

Nah, I propose myZval->String() for when the zval is a string (which should be determined by myZval->IsString()) and myZval->AsString() to proxy convert_to_string. That’s a valid question.

    • If it’s literally a class wrapper around a zval for linking or whatever reasons to avoid the zend_print_zval vs. print issues, what policies, defensive coding techniques, etc. do we need in place so the next guy 2 years from now doesn’t think it’s a good idea to add a print method because he wasn’t around for this whole discussion?

There would be little downsides to adding a print member method, especially if all it does is call zend_print_zval.(other than more code we have to maintain, which again applies to all changes).

    • Is this proposal literally limited to zval or are you suggesting a collection of classes around various engine structs? If the proposal were to be adopted to accept your zval class, would you propose other changes? It seems like this is a never-ending road…

Finally – let’s be really clear here about something – it’s not the community’s job to say yes to you, it’s your job to convince the community. The best way you can do that is a well thought out RFC that shows the community you have put in the necessary time and consideration to making such a fundamental addition to the engine.

That is a ridiculous expectation to have on both sides. No, I don’t expect the community to just say yes to me, but I expect valid reasons for saying no to my proposal, not just “someone will have to maintain it” and “C++ is obsolete so this is pointless”. It is just as ridiculous as expecting me to whole RFC simply to introduce an idea. Even the RFC guide requires a discussion first, unless I am missing something.

No one, including me, is looking to make it unnecessarily difficult to use C++ to write extensions,

Are you sure about that?

but the difficulty that exists today is because trying to come up with smart solutions to questions such as above is hard.

Says who?

I certainly welcome you to contribute here if you believe you have a good idea with the above in mind, as long as you can do it respectfully.

John

On Aug 15 2024, at 2:50 pm, Lanre <lnearwaju@gmail.com> wrote:

Hi John,

Thanks for reaching out to me directly—I really appreciate it. I’m a C++ developer and don’t work with PHP professionally; it’s something I do for personal projects and scripts. I had a week off and decided to create something that could make life easier for C++ developers like myself when writing extensions.

The issue isn’t just that certain implementations are repeatedly being recreated; it’s also that this repetition breaks portability for C++ extensions. You can’t use standard library containers without ensuring your class or struct adheres to specific rules. This leaves you with two options:

  1. Write a wrapper class that extends zval to make it compatible (which is my usual approach).

  2. Override global operators for zval, which is problematic as you still won’t have a constructor or destructor. If another extension does this, it’s undefined behavior.

Option A works well, but I have to do this for each extension I write. The problem is that even though these new subclasses in each extension are practically identical, they’re not compatible with each other without linking all the extensions or a common object file that defines this. This introduces a dependency that isn’t Zend/PHP, which is why I don’t bother shipping some of them.

You seemed to assume I wasn’t willing to maintain my code—isn’t that a given? Or do you think I believe code just works without maintenance? Your point about someone needing to maintain APIs and ensure parity with C APIs applies to any change made to the engine, so why keep bringing it up?

You said this could be done outside the core, but that’s not true. If it’s done outside, it will be incompatible with other external implementations. This is part of my frustration. You write C++ “when the need arises”; meanwhile, I’m paid $300k a year to do so. You lack the experience to confidently say, “this could easily be done outside of core”—you’re essentially guessing. How many C++ extensions have you written? How many times have you encountered and solved this issue?

I’m volunteering for this, with only a day left of my week off, which means I probably won’t be pursuing the RFC until the next opportunity I get. So, thanks for that.

Lanre

On Thu, Aug 15, 2024 at 12:13 PM John Coggeshall <john@coggeshall.org> wrote:

Lanre,

I’m taking this off list because I want to try to take down the temperature here a bit. I don’t know why you are so angry, but I will assure you I do know something significant of what I’m talking about. Not only do I write C code, but I also write C++ code when the need arises, and I do have legitimate concerns regarding the idea of introducing a separate C++ API into the engine. I’ve been involved in this project since 1996 – I am a core developer “alum” who has made significant contributions to this code base (for example, see ext/tidy ) – these opinions don’t come out of no where. In fact, you aren’t even the first person if you want to go back into the archives to even bring up this argument of more C++ support.

The things I am talking about matter. Someone has to maintain whatever APIs you want to introduce, someone has to maintain parity with the C APIs every time they are changed, and all of that is a lot of work. Maybe that work is worth the effort, maybe not – I personally don’t believe it is – especially when I think this could easily be done outside of core. Either way, if you want to be successful in an Open Source project you need to dial back your rhetoric. Not only because it makes the list a toxic place where volunteers are giving the project their time, but also because it completely undermines any legitimate argument you might have. I hope you will take a breath and chill out. This is not useful, helpful, or appropriate behavior.

John

On 15 August 2024 18:42:58 BST, Lanre <lnearwaju@gmail.com> wrote:

On Thu, Aug 15, 2024 at 11:33 AM Derick Rethans <derick@php.net> wrote:

On 15 August 2024 18:10:11 BST, Lanre <lnearwaju@gmail.com> wrote:

>You're embarrassing yourself John, read my very first paragraph (you got
this).

We have said this before, but you *really* need to stop using
condescending language, and ad-hominems like this.

Then maybe he should stop embarrassing himself. How many times do you want
me to repeat myself? How did he miss my introductory paragraph, while
quoting that same email, to ask me a question that is answered in that
paragraph? That isn't considered an attack? But calling that
embarrassing is? My bad.

Despite the request to stop your style of your communication, you yet continued. You don't get to play the victim.

And then you thought it cool to make public a private conversation without consent.

Consider this your last warning.

cheers
Derick

On Thu, Aug 15, 2024 at 4:39 PM Derick Rethans <derick@php.net> wrote:

On 15 August 2024 18:42:58 BST, Lanre <lnearwaju@gmail.com> wrote:

On Thu, Aug 15, 2024 at 11:33 AM Derick Rethans <derick@php.net> wrote:

On 15 August 2024 18:10:11 BST, Lanre <lnearwaju@gmail.com> wrote:

You’re embarrassing yourself John, read my very first paragraph (you got
this).

We have said this before, but you really need to stop using
condescending language, and ad-hominems like this.

Then maybe he should stop embarrassing himself. How many times do you want
me to repeat myself? How did he miss my introductory paragraph, while
quoting that same email, to ask me a question that is answered in that
paragraph? That isn’t considered an attack? But calling that
embarrassing is? My bad.

Despite the request to stop your style of your communication, you yet continued. You don’t get to play the victim.

And then you thought it cool to make public a private conversation without consent.

Consider this your last warning.

cheers
Derick

I am starting to feel a little attacked, watch your tone.