# WIKI: phpng-upgrading

- Thread: https://externals.io/message/90745
- Original archive: https://news-web.php.net/php.internals/90745
- Started by Yasuo Ohgaki on 2016-01-20T21:55:41+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #90745 — Yasuo Ohgaki — 2016-01-20T21:55:41+00:00

URL: https://externals.io/message/90745#90745

Hi ZendEngine developers,

I'm not sure if the wiki page is maintained, but I noticed few errors.

https://wiki.php.net/phpng-upgrading#strings
has following example.

- ZVAL_STRING(zv, str, 1);
+ ZVAL_STRING(zv, str);

- ZVAL_STRINGL(zv, str, len, 1);
+ ZVAL_STRINGL(zv, str, len);

- ZVAL_STRING(zv, str, 0);
+ ZVAL_STRING(zv, str);
+ efree(str);

- ZVAL_STRINGL(zv, str, len, 0);
+ ZVAL_STRINGL(zv, str, len);
+ efree(str);

Since PHP5 has following definition for ZVAL_STRING*()

#define ZVAL_STRING(z, s, duplicate) do {    \
        const char *__s=(s);                \
        zval *__z = (z);                    \
        Z_STRLEN_P(__z) = strlen(__s);        \
        Z_STRVAL_P(__z) = (duplicate?estrndup(__s,
Z_STRLEN_P(__z)):(char*)__s);\
        Z_TYPE_P(__z) = IS_STRING;            \
    } while (0)

the example's 0 and 1 are flipped, efree() locations are wrong.

In https://wiki.php.net/phpng-upgrading#zend_string_api ,
it says

zend_string_init(char *val, int len, int persistent)

Current definition is

zend_string_init(char *val, size_t len, int persistent)

Should I update the doc or is the doc is maintained
elsewhere?

Regards

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #90747 — Sean DuBois — 2016-01-20T22:07:03+00:00

URL: https://externals.io/message/90745#90747 · In reply to: #90745

> Hi ZendEngine developers,
>
> I'm not sure if the wiki page is maintained, but I noticed few errors.
>
> https://wiki.php.net/phpng-upgrading#strings
> has following example.
>
> - ZVAL_STRING(zv, str, 1);
> + ZVAL_STRING(zv, str);
>
> - ZVAL_STRINGL(zv, str, len, 1);
> + ZVAL_STRINGL(zv, str, len);
>
> - ZVAL_STRING(zv, str, 0);
> + ZVAL_STRING(zv, str);
> + efree(str);
>
> - ZVAL_STRINGL(zv, str, len, 0);
> + ZVAL_STRINGL(zv, str, len);
> + efree(str);
>
> Since PHP5 has following definition for ZVAL_STRING*()
>
> #define ZVAL_STRING(z, s, duplicate) do {    \
>         const char *__s=(s);                \
>         zval *__z = (z);                    \
>         Z_STRLEN_P(__z) = strlen(__s);        \
>         Z_STRVAL_P(__z) = (duplicate?estrndup(__s,
> Z_STRLEN_P(__z)):(char*)__s);\
>         Z_TYPE_P(__z) = IS_STRING;            \
>     } while (0)
>
> the example's 0 and 1 are flipped, efree() locations are wrong.
>
> In https://wiki.php.net/phpng-upgrading#zend_string_api ,
> it says
>
> zend_string_init(char *val, int len, int persistent)
>
> Current definition is
>
> zend_string_init(char *val, size_t len, int persistent)
>
> Should I update the doc or is the doc is maintained
> elsewhere?
>
> Regards
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
>
> --
> 
> 
>

Hi!

I tried to get access to that page as well, but didn't have any luck
would you mind adding the zend_parse_paramaters changes?

'l' went from 'long' -> 'zend_long' and 's' went from 'int' -> 'size_t'.

So many extensions have been ported without this in mind, and it bites
in really nasty hard to reproduce runtime ways.

thanks!

---

## #90750 — Yasuo Ohgaki — 2016-01-20T22:19:29+00:00

URL: https://externals.io/message/90745#90750 · In reply to: #90747

Hi Sean,


>
> I tried to get access to that page as well, but didn't have any luck
> would you mind adding the zend_parse_paramaters changes?
>
> 'l' went from 'long' -> 'zend_long' and 's' went from 'int' -> 'size_t'.
>
> So many extensions have been ported without this in mind, and it bites
> in really nasty hard to reproduce runtime ways.

Good point.
zend_parse_parameters() is using "size_t" for string length, since
zend_string uses size_t for it.

struct _zend_string {
    zend_refcounted_h gc;
    zend_ulong        h;                /* hash value */
    size_t            len;
    char              val[1];
};

AFAIK, PHP7 repo's function parameters are changed to size_t.
This should be described in upgrading doc for 3rd party module
developers.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #90751 — Nikita Popov — 2016-01-20T22:28:42+00:00

URL: https://externals.io/message/90745#90751 · In reply to: #90745

> Hi ZendEngine developers,
>
> I'm not sure if the wiki page is maintained, but I noticed few errors.
>
> https://wiki.php.net/phpng-upgrading#strings
> has following example.
>
> - ZVAL_STRING(zv, str, 1);
> + ZVAL_STRING(zv, str);
>
> - ZVAL_STRINGL(zv, str, len, 1);
> + ZVAL_STRINGL(zv, str, len);
>
> - ZVAL_STRING(zv, str, 0);
> + ZVAL_STRING(zv, str);
> + efree(str);
>
> - ZVAL_STRINGL(zv, str, len, 0);
> + ZVAL_STRINGL(zv, str, len);
> + efree(str);
>
> Since PHP5 has following definition for ZVAL_STRING*()
>
> #define ZVAL_STRING(z, s, duplicate) do {    \
>         const char *__s=(s);                \
>         zval *__z = (z);                    \
>         Z_STRLEN_P(__z) = strlen(__s);        \
>         Z_STRVAL_P(__z) = (duplicate?estrndup(__s,
> Z_STRLEN_P(__z)):(char*)__s);\
>         Z_TYPE_P(__z) = IS_STRING;            \
>     } while (0)
>
> the example's 0 and 1 are flipped, efree() locations are wrong.
>

These examples are correct. In PHP 7 ZVAL_STRING always duplicates, which
is what the 1 parameter used to signify.


> In https://wiki.php.net/phpng-upgrading#zend_string_api ,
> it says
>
> zend_string_init(char *val, int len, int persistent)
>
> Current definition is
>
> zend_string_init(char *val, size_t len, int persistent)
>
> Should I update the doc or is the doc is maintained
> elsewhere?
>

I've fixed this. But yes, you should update the doc, it's not maintained
elsewhere.

Thanks,
Nikita

---

## #90752 — Yasuo Ohgaki — 2016-01-20T22:37:18+00:00

URL: https://externals.io/message/90745#90752 · In reply to: #90751

Hi Nikita,


> These examples are correct. In PHP 7 ZVAL_STRING always duplicates, which is
> what the 1 parameter used to signify.

Oh, now I see the example intention.
Thank you.

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #90755 — Andrea Faulds — 2016-01-20T23:39:06+00:00

URL: https://externals.io/message/90745#90755 · In reply to: #90745

Hi Yasuo,

Yasuo Ohgaki wrote:
> Hi ZendEngine developers,
>
> I'm not sure if the wiki page is maintained, but I noticed few errors.
>
> https://wiki.php.net/phpng-upgrading#strings

phpng-upgrading was written back when it was just phpng and the 64-bit 
patch wasn't merged. Heck, I don't think phpng was merged into master at 
that point either.

Given it's now needed for PHP 7 migration, maybe we should move it into 
UPGRADING.INTERNALS or onto the PHP manual?

Thanks.
-- 
Andrea Faulds
https://ajf.me/

---

## #90791 — Nikita Popov — 2016-01-21T16:19:08+00:00

URL: https://externals.io/message/90745#90791 · In reply to: #90747

> Hi!
>
> I tried to get access to that page as well, but didn't have any luck
> would you mind adding the zend_parse_paramaters changes?
>
> 'l' went from 'long' -> 'zend_long' and 's' went from 'int' -> 'size_t'.
>
> So many extensions have been ported without this in mind, and it bites
> in really nasty hard to reproduce runtime ways.
>

I've added these two to the zpp section, thanks!

Nikita
