Am 13.04.2015 um 18:48 schrieb Cesar Rodas:
> Instead of having a method, why don't we allow body expr to be
evaluated as we see things in the Class definition?
>
> <?php
>
> class foobar
> {
>     static protected $conn = new mysqli('localhost', 'my_user',
'my_password', 'my_db');
> }
>
> It's cleaner but it breaks compatibility with everything :-(
>
> --
> César D. Rodas
> Open Source developer
> +595-983-161124
> PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6

Hello César,

you accidently wrote this answer only to me, so I forward this to the
mailing list together with my answer.

First of all I would not store any resource handle, like a mysql
connection you did in your example, directly to a static member. (Will
add another point on this to the discussion-section the next days)

https://wiki.php.net/rfc/static_class_constructor#discussions

Second point is that with your suggested syntax only single methods can
be used to initialize the static member. With my proposal you will be
able to do more complex initialization algorithms. For example open a
config-file with fopen, read the content to a static member and close
the config-file again with fclose.

Regards

--
DerOetzi

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to