# Calling a class constructor

- Thread: https://externals.io/message/37366
- Original archive: https://news-web.php.net/php.internals/37366
- Started by Sam Barrow on 2008-04-30T16:57:41+00:00
- Messages: 9
- 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

---

## #37366 — Sam Barrow — 2008-04-30T16:57:41+00:00

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

Currently there is no way to call a class constructor using
call_user_func or something similar, the only way is to use a reflection
object which is useless overhead and takes a few lines of code.

This would be very useful to be able to do

create_new(string $class, array $constructor_args)

Does anyone else see a need for this?

---

## #37368 — Stanislav Malyshev — 2008-04-30T17:03:29+00:00

URL: https://externals.io/message/37366#37368 · In reply to: #37366

Hi!

> create_new(string $class, array $constructor_args)

You can create new object via ReflectionClass::newInstance.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37370 — Sam Barrow — 2008-04-30T17:05:39+00:00

URL: https://externals.io/message/37366#37370 · In reply to: #37368

> Hi!
> 
> > […]
> 
> You can create new object via ReflectionClass::newInstance.

Still, that just seems unnecessary, I usually compile without the
reflection stuff because i never use it. I'd like to be able to use this
like call_user_func, I'm pretty much doing the same thing.

> -- 
> Stanislav Malyshev, Zend Software Architect
> stas@zend.com   http://www.zend.com/
> (408)253-8829   MSN: stas@zend.com

---

## #37371 — Hannes Magnusson — 2008-04-30T17:09:26+00:00

URL: https://externals.io/message/37366#37371 · In reply to: #37366

>  create_new(string $class, array $constructor_args)
>
>  Does anyone else see a need for this?

No.
Have you considered subscribing to php-general@?

Could you please first direct these questions to php-general@ and
gather feedback from there before you post it here?
You have been causing a massive amount of completely useless mails for
the last weeks, which is getting very annoying.
If you could first discuss these things on the general user list, or
even do a quick poll on your blog, before bringing them further into
the internals development list I would really appreciate it.

-Hannes

---

## #37374 — Sam Barrow — 2008-04-30T17:15:54+00:00

URL: https://externals.io/message/37366#37374 · In reply to: #37371

> 
> > […]
> 
> No.
> Have you considered subscribing to php-general@?
> 
> Could you please first direct these questions to php-general@ and
> gather feedback from there before you post it here?
> You have been causing a massive amount of completely useless mails for
> the last weeks, which is getting very annoying.
> If you could first discuss these things on the general user list, or
> even do a quick poll on your blog, before bringing them further into
> the internals development list I would really appreciate it.

I emailed about return type hinting, array access on function returns (1
or 2 emails), and calling class constructors dynamically (1 email). I
want to see if there's a need for any of this and then submit a patch,
I'm not just talking; I've spent quite a bit of time writing code.

PHP generals isn't going to help me with any of this, they're going to
tell me what I already know.

> -Hannes

---

## #37384 — Lars Strojny — 2008-04-30T19:17:07+00:00

URL: https://externals.io/message/37366#37384 · In reply to: #37370

Hi all, esp. Johannes,

Am Mittwoch, den 30.04.2008, 13:05 -0400 schrieb Sam Barrow:
[...]
> Still, that just seems unnecessary, I usually compile without the
> reflection stuff because i never use it. I'd like to be able to use this
> like call_user_func, I'm pretty much doing the same thing.

Oh, good hint. As the we already have hard enabling changes (SPL, PCRE)
in 5.3, shouldn't we force enabling reflections?

cu, Lars

---

## #37385 — Antony Dovgal — 2008-04-30T19:22:19+00:00

URL: https://externals.io/message/37366#37385 · In reply to: #37384

> Hi all, esp. Johannes,
> 
> Am Mittwoch, den 30.04.2008, 13:05 -0400 schrieb Sam Barrow:
> [...]
> > […]
>
> Oh, good hint. As the we already have hard enabling changes (SPL, PCRE)
> in 5.3, shouldn't we force enabling reflections?

Yes, I believe a feature like this should be always enabled, 
as it's actually a part of the language/engine.

-- 
Wbr, 
Antony Dovgal

---

## #37399 — Marcus Boerger — 2008-05-02T10:03:52+00:00

URL: https://externals.io/message/37366#37399 · In reply to: #37385

Hello Antony, Johannes,

seeing this thread I agree. So that makes the list: PCRE, Reflection, SPL.
Johannes?


Wednesday, April 30, 2008, 9:22:19 PM, you wrote:

> 
> > […]

> Yes, I believe a feature like this should be always enabled, 
> as it's actually a part of the language/engine.

> -- 
> Wbr, 
> Antony Dovgal




Best regards,
 Marcus

---

## #37400 — johannes@php.net — 2008-05-02T11:29:20+00:00

URL: https://externals.io/message/37366#37400 · In reply to: #37399

> Hello Antony, Johannes,
> 
> seeing this thread I agree. So that makes the list: PCRE, Reflection, SPL.
> Johannes?

I was under the impression that was already the case for Reflection, so
I don't mind.

johannes
