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

  • Home
  • SEARCH
  • 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 560867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:23:21+00:00 2026-05-13T12:23:21+00:00

Writing a PHP extension in C, I want to convert a userland object (

  • 0

Writing a PHP extension in C, I want to convert a userland object (IS_OBJECT) to a string through __toString() if it has one, and fail otherwise. What should I use?
I don’t need another zval on output, just a char *.

zval *zo;

switch (Z_TYPE_P(zo)) {
case IS_STRING:
    ... Z_STRVAL_P(zo) ...
    break;
case IS_OBJECT:
    ... ???(zo) ...
    break;
...
}
  • 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-05-13T12:23:22+00:00Added an answer on May 13, 2026 at 12:23 pm

    The reflection module does something like

    ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1, 1);
    result= call_user_function_ex(NULL, &object, &fname, &retval_ptr, 0, NULL, 0, NULL TSRMLS_CC);
    zval_dtor(&fname);
    
    if (result == FAILURE) {
        _DO_THROW("Invocation of method __toString() failed");
        /* Returns from this function */
    }
    

    And then you’d extract the char* with Z_STRVAL_P().
    But I guess you could also use

    case IS_OBJECT:
      if ( SUCCESS==zend_std_cast_object_tostring(uservar, uservar, IS_STRING TSRMLS_CC) ) {
        int len = Z_STRLEN_P(uservar);
        char* pValue = Z_STRVAL_P(uservar);
        ...
      }
    

    zend_std_cast_object_tostring() is implemented in zend/zend_object_handlers.c. You might want to check if it really does what you want

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

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you considered creating a Custom Control for each type… May 13, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer InputStream cannot be flushed. Why do you want to do… May 13, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer TFS is a great source control tool for every organization.… May 13, 2026 at 8:35 pm

Related Questions

Hey. I'm taking a course titled Principles of Programming Languages, and I need to
I have written a PHP extension library in C++. I am writing the extension
Update: I have now written a PHP extension called php_ssdeep for the ssdeep C
I'm writing a PHP5 extension, and while I could write it in C, it
I am coding a web application in PHP and it has some performance intensive

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.