Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:19:23+00:00 2026-06-01T01:19:23+00:00

I’ve been a pretty long time PHP developer, and I’m starting to hit some

  • 0

I’ve been a pretty long time PHP developer, and I’m starting to hit some limitations within the language. So, with that being said, I figured the next step in my development cycle would be to move onto C++, and build out some extensions!

As I went through some standard “Hello World” like tutorials, everything seems to make sense for the most part. I built a fairly decent tic-tac-toe application, so I figured it was time to start diving into PECL and see how things were working. What I found however, kind of blows my mind.

Can anyone please explain both the purpose and reasoning to why something like this:

PHP_FUNCTION(helloWorld)
{
    RETURN_STRING("Hello World");
}

isn’t more along the lines of this:

string helloWorld()
{
    return "Hello World"
}

PHP_REGISTER_METHOD("helloWorld");

I’m not pretending that I know more than the people that created the language, and I’m not trying to stir up any trouble. It just seems (at least from a beginners perspective) that creating a PHP extension isn’t anything like writing a C++ program. It’s almost a different language completely, aside from some basic syntax rules.

Any help would be appreciated. Just a beginner trying to grow 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:19:25+00:00Added an answer on June 1, 2026 at 1:19 am

    PHP extension development does not differ that much from other C/C++ development. The only thing that is special is that you have to interface the PHP scripting world with your C/C++ functions. This task is not trivial, and here is where the weird macros such as PHP_FUNCTION are required.

    For example, if you want to call a function “helloWorld” from PHP, the interpreter needs to lookup “helloWorld” and map it to a C function. This function needs to have a certain signature, that means it has to accept a certain set of parameters, and must return a certain value. This is not arbitrary and the interpreter cannot just call any C/C++ function.

    This is just how low-level languages like C work, you cannot “inspect” what kind of arguments a function takes.

    In particular, all values in the PHP interpreter are special structs that cannot be converted to C++ types. A PHP string is something different than a C++ std::string. The PHP API provides all kinds of tools to convert values, but you have to know how to use them.

    Once you know how to write a C function that can be called from PHP, you are in “C/C++ world”, where you can call another C/C++ function and use C/C++ types. From here on, it’s just as writing pure C/C++ apps. Well, until you have to return values back to PHP world, where you have to use the PHP API tools again.

    There are tools that can make your life easier, by helping in generating the required “glue code” to interface a scripting language such as PHP and “pure” C++ projects. Take a look at SWIG, which is probably the most prominent example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.