Novice Question [message #180587] |
Sun, 03 March 2013 22:10 |
daveh
Messages: 18 Registered: March 2013
Karma: 0
|
Junior Member |
|
|
Hello
I'm doing some maintenance/upgrade of some old php4.3 code and I ran
across the following code snippet:
$gvns = (array)$gvns;
What it exactly is happening here? what does (array) mean?
never seen anything like this before.
Dave
|
|
|
|
Re: Novice Question [message #180589 is a reply to message #180588] |
Mon, 04 March 2013 00:52 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
Gregor Kofler wrote:
> Am 03.03.2013 23:10, David Heller meinte:
>> I'm doing some maintenance/upgrade of some old php4.3 code and I ran
>> across the following code snippet:
>> $gvns = (array)$gvns;
>> What it exactly is happening here? what does (array) mean?
>> never seen anything like this before.
>
> Type casting.
ACK.
> (It's the same as $gvns = array($gvns); )
Evidently it is not.
$ php -r 'class C {}; print_r((array) new C()); print_r(array(new C()));'
Array
(
)
Array
(
[0] => C Object
(
)
)
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
|
|
|
Re: Novice Question [message #180591 is a reply to message #180587] |
Mon, 04 March 2013 10:31 |
Captain Paralytic
Messages: 204 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Mar 3, 10:10 pm, David Heller <da...@allheller.net> wrote:
> Hello
>
> I'm doing some maintenance/upgrade of some old php4.3 code and I ran
> across the following code snippet:
> $gvns = (array)$gvns;
> What it exactly is happening here? what does (array) mean?
> never seen anything like this before.
>
> Dave
It is a construct often used to change object properties into an
associative array. Another method (which may have slightly different
results) is to use the get_object_vars() function. Search Google for
php get_object_vars vs array cast
to see discussions on the differences.
|
|
|
Re: Novice Question [message #180595 is a reply to message #180589] |
Mon, 04 March 2013 22:12 |
Gregor Kofler
Messages: 69 Registered: September 2010
Karma: 0
|
Member |
|
|
Am 04.03.2013 01:52, Thomas 'PointedEars' Lahn meinte:
> Gregor Kofler wrote:
>
>> Am 03.03.2013 23:10, David Heller meinte:
>>> I'm doing some maintenance/upgrade of some old php4.3 code and I ran
>>> across the following code snippet:
>>> $gvns = (array)$gvns;
>>> What it exactly is happening here? what does (array) mean?
>>> never seen anything like this before.
>>
>> Type casting.
>
> ACK.
>
>> (It's the same as $gvns = array($gvns); )
>
> Evidently it is not.
Indeed. My claim is only valid for scalar values.
Gregor
|
|
|