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 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

Related Questions

I am writing PHP code where I want to pass the session id myself
I'm writing my first PHP app that has to directly deal with dates, and
I've been writing PHP for about six years now and have got to a
I've been writing PHP web applications for some time, and have come across very
I'm writing a PHP script and the script outputs a simple text file log
I'm writing a PHP application with testability in mind, so my classes always ask
I'm writing a php app to access a MySQL database, and on a tutorial,
I was thinking of writing a PHP script that would analyse a CMS'd page's
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Is there any advantage to writing a PHP conditional like this: if ($variable !=

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.