# Please confirm behaviour of ZEND_ACC_STATIC

- Thread: https://externals.io/message/10871
- Original archive: https://news-web.php.net/php.internals/10871
- Started by l0t3k on 2004-07-02T13:50:18+00:00
- Messages: 3
- 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

---

## #10871 — l0t3k — 2004-07-02T13:50:18+00:00

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

in my extension, i have a class which has methods which work slightly
differently depending on whether or not they are called statically.
as an example :

   $original = new UnicodeString("HELLO WORLD","utf8");
   $lower = UnicodeString::toLowerCase($original);    /* returns a new copy
*/
   $lower1 = $original->toLowerCase();  /* original is lowercased. return a
reference */

 the latter is for efficiency. imagine chains like
       print_r($original->reverse()->toTitleCase()->split(" "));  /* no
intermediaries created  work on $original*/

while the former allows for transformations without affecting the original
string.

since the method can behave statically, it is marked as ZEND_ACC_STATIC.
however it appears that once marked as such,
getThis() always reports NULL. i've confirmed that marking it as non static
cause the object to be properly passed.

is this a WAD. if so, is it possible (at least for internal functions) for a
method to be called statically as well as in an object context ?

l0t3k

---

## #10874 — Andrey Hristov — 2004-07-02T14:51:36+00:00

URL: https://externals.io/message/10871#10874 · In reply to: #10871

Quoting l0t3k <cshmoove@bellsouth.net>:

> in my extension, i have a class which has methods which work slightly
> differently depending on whether or not they are called statically.
> as an example :
>
>    $original = new UnicodeString("HELLO WORLD","utf8");
>    $lower = UnicodeString::toLowerCase($original);    /* returns a new copy
> */
>    $lower1 = $original->toLowerCase();  /* original is lowercased. return a
> reference */
>
>  the latter is for efficiency. imagine chains like
>        print_r($original->reverse()->toTitleCase()->split(" "));  /* no
> intermediaries created  work on $original*/
>
> while the former allows for transformations without affecting the original
> string.
>
> since the method can behave statically, it is marked as ZEND_ACC_STATIC.
> however it appears that once marked as such,
> getThis() always reports NULL. i've confirmed that marking it as non static
> cause the object to be properly passed.

Yepp, I have experienced this and forced myself to add methodNameS (the S is for
static)
method to have static calls available.

> is this a WAD. if so, is it possible (at least for internal functions) for a
> method to be called statically as well as in an object context ?
>
> l0t3k
>

andrey

---

## #10876 — Marcus Boerger — 2004-07-02T18:14:24+00:00

URL: https://externals.io/message/10871#10876 · In reply to: #10871

Hello l0t3k,

never ever mix static and non static methods!
The only reason this is possible is for having BC for old
bullshit concepts. Apart from that use ZEND_ACC_ALLOW_STATIC
if you really want that behavior but before you do think
twice and again and then again if there is no correct way...

marcus

Friday, July 2, 2004, 3:50:18 PM, you wrote:

> in my extension, i have a class which has methods which work slightly
> differently depending on whether or not they are called statically.
> as an example :

>    $original = new UnicodeString("HELLO WORLD","utf8");
>    $lower = UnicodeString::toLowerCase($original);    /* returns a new copy
> */
>    $lower1 = $original->toLowerCase();  /* original is lowercased. return a
> reference */

>  the latter is for efficiency. imagine chains like
>        print_r($original->reverse()->toTitleCase()->split(" "));  /* no
> intermediaries created  work on $original*/

> while the former allows for transformations without affecting the original
> string.

> since the method can behave statically, it is marked as ZEND_ACC_STATIC.
> however it appears that once marked as such,
> getThis() always reports NULL. i've confirmed that marking it as non static
> cause the object to be properly passed.

> is this a WAD. if so, is it possible (at least for internal functions) for a
> method to be called statically as well as in an object context ?

> l0t3k




-- 
Best regards,
 Marcus                            mailto:helly@php.net
