PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > pointers vs. objects
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
pointers vs. objects

Réponse
 
LinkBack Outils de la discussion
Vieux 20/06/2008, 05h37   #1
laredotornado@zipmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut pointers vs. objects

Hi,

I'm using PHP 5. How do I tell if an array contains objects or
pointers to objects?

Thanks, - Dave
  Réponse avec citation
Vieux 20/06/2008, 09h28   #2
Erwin Moller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

laredotornado@zipmail.com schreef:
> Hi,
>
> I'm using PHP 5. How do I tell if an array contains objects or
> pointers to objects?


Hi,

Start with dumping the array, using print_r().
eg:

// $mysteryArr = ???;
then:

echo "<pre>";
print_r($mysteryArr);
echo "</pre>";


>
> Thanks, - Dave


Regards,
Erwin Moller
  Réponse avec citation
Vieux 20/06/2008, 09h47   #3
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

laredotornado@zipmail.com wrote:
> Hi,
>
> I'm using PHP 5. How do I tell if an array contains objects or
> pointers to objects?


1) References are not pointers.
2) Be it reference or not, you access the objects in exactly the same way.

Why do you need this? In PHP 5 objects are always passed by reference
BTW, so usually you don't need no weird &'s for that.

Var_dump will show a & if something is a reference.
--
Rik Wasmus
....moving deadlines for your pleasure.
  Réponse avec citation
Vieux 20/06/2008, 13h21   #4
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

Rik Wasmus wrote:
> laredotornado@zipmail.com wrote:
>> Hi,
>>
>> I'm using PHP 5. How do I tell if an array contains objects or
>> pointers to objects?

>
> 1) References are not pointers.
> 2) Be it reference or not, you access the objects in exactly the same way.
>
> Why do you need this? In PHP 5 objects are always passed by reference
> BTW, so usually you don't need no weird &'s for that.


That makes sense. Is that the only thing passed by reference?

Jeff
>
> Var_dump will show a & if something is a reference.

  Réponse avec citation
Vieux 20/06/2008, 13h59   #5
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

Jeff wrote:
> Rik Wasmus wrote:
>> laredotornado@zipmail.com wrote:
>>> Hi,
>>>
>>> I'm using PHP 5. How do I tell if an array contains objects or
>>> pointers to objects?

>>
>> 1) References are not pointers.
>> 2) Be it reference or not, you access the objects in exactly the same
>> way.
>>
>> Why do you need this? In PHP 5 objects are always passed by reference
>> BTW, so usually you don't need no weird &'s for that.

>
> That makes sense. Is that the only thing passed by reference?


- Objects are passed by reference by default.
- Arrays & scalars are only passed by reference it explicitly set (&).
- Resources are a a league of their own, just check what their
associated functions do. Sometimes, having references to them does matter:

<?php
$h = fopen(__FILE__,'r');
$a = &$h;
$b = $h;
var_dump($h,$a,$b);
fclose($h);
var_dump($h,$a,$b);
fclose($a);
var_dump($h,$a,$b);
?>
--
Rik Wasmus
....moving deadlines for your pleasure.
  Réponse avec citation
Vieux 20/06/2008, 18h14   #6
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

..oO(Rik Wasmus)

>Jeff wrote:
>
>> That makes sense. Is that the only thing passed by reference?

>
>- Objects are passed by reference by default.


It should be mentioned and kept in mind that these are _not_ the same
references as created with an explicit '&', but internal object handles.
'=' and '=&' are still two different things, even when working with
objects in PHP 5.

See example #6 (Object Assignment) on

http://de2.php.net/manual/en/language.oop5.basic.php

for a short demonstration of the differences.

Micha

PS: Anyone else having problems with <http://www.php.net> currently?
Ping and traceroute work from here, but the web server doesn't want to
talk with me ...
  Réponse avec citation
Vieux 20/06/2008, 19h42   #7
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

On Fri, 20 Jun 2008 19:14:10 +0200, Michael Fesser <netizen@gmx.de> wrote:

> .oO(Rik Wasmus)
>
>> Jeff wrote:
>>
>>> That makes sense. Is that the only thing passed by reference?

>>
>> - Objects are passed by reference by default.

>
> It should be mentioned and kept in mind that these are _not_ the same
> references as created with an explicit '&', but internal object handles.
> '=' and '=&' are still two different things, even when working with
> objects in PHP 5.
>
> See example #6 (Object Assignment) on
>
> http://de2.php.net/manual/en/language.oop5.basic.php
>
> for a short demonstration of the differences.


Yup, that's why I asked why he needed it for.

> PS: Anyone else having problems with <http://www.php.net> currently?
> Ping and traceroute work from here, but the web server doesn't want to
> talk with me ...


That's been the case for me for months, the server being either very slow
or not responsive at all, although it just seemed to get better the last
few days. I've just grown accustomed to using nl2. or nl3.
--
Rik Wasmus
....spamrun finished
  Réponse avec citation
Vieux 22/06/2008, 00h33   #8
AnrDaemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: pointers vs. objects

Greetings, Michael Fesser.
In reply to Your message dated Friday, June 20, 2008, 21:14:10,

> PS: Anyone else having problems with <http://www.php.net> currently?
> Ping and traceroute work from here, but the web server doesn't want to
> talk with me ...


I've had problem with ru2, but that was a DNS change, what my DNS server
wasn't reflected. I've forced it to recheck DNS records and it is ok now.
No problem with www.php.net for long time.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h37.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,20434 seconds with 16 queries