FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Novice Question
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Novice Question [message #180587] Sun, 03 March 2013 22:10 Go to next message
daveh is currently offline  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 #180588 is a reply to message #180587] Sun, 03 March 2013 23:38 Go to previous messageGo to next message
Gregor Kofler is currently offline  Gregor Kofler
Messages: 69
Registered: September 2010
Karma: 0
Member
Am 03.03.2013 23:10, David Heller meinte:
>
> 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.

Type casting. (It's the same as $gvns = array($gvns); )

< http://www.php.net/manual/en/language.types.array.php#language.types.array. casting>


Gregor
Re: Novice Question [message #180589 is a reply to message #180588] Mon, 04 March 2013 00:52 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  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 Go to previous messageGo to next message
Captain Paralytic is currently offline  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 Go to previous message
Gregor Kofler is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: XML error when accessing a certain method of a wsdl service
Next Topic: Dynamically change video URLs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun May 26 08:57:37 GMT 2024

Total time taken to generate the page: 0.02806 seconds