# Problems on PHP5 object instantiation

- Thread: https://externals.io/message/27518
- Original archive: https://news-web.php.net/php.internals/27518
- Started by Jingcheng Zhang on 2007-01-18T14:06:11+00:00
- Messages: 2
- 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

---

## #27518 — Jingcheng Zhang — 2007-01-18T14:06:11+00:00

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

Hi,
    I'm now trying OOP in PHP5, and enjoy it very much. However, as we know
PHP5 does not allow compile-time instantiation,
so when I try this script:

<?php
class C {
    static private $o = new stdClass();
}
?>

it ends up with a parse error, while in Java it works naturally. I wonder
whether there are some difficulties on implementing this
feature, or, is it just not the natural way? Thanks :)

-- 
Best regards,
Jingcheng Zhang
Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University
P.R.China

---

## #27520 — Antony Dovgal — 2007-01-18T14:21:00+00:00

URL: https://externals.io/message/27518#27520 · In reply to: #27518

> Hi,
>     I'm now trying OOP in PHP5, and enjoy it very much. However, as we know
> PHP5 does not allow compile-time instantiation,
> so when I try this script:
> 
> <?php
> class C {
>     static private $o = new stdClass();
> }
> ?>

Class properties are initialized in compile time, therefore they cannot be 
initialized with expressions, which are executed in runtime.

-- 
Wbr, 
Antony Dovgal
