Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46475 Return-Path: <0xcafefeed@gmail.com> Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72133 invoked from network); 19 Dec 2009 19:29:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Dec 2009 19:29:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=0xcafefeed@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=0xcafefeed@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.212 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: 0xcafefeed@gmail.com X-Host-Fingerprint: 209.85.219.212 mail-ew0-f212.google.com Received: from [209.85.219.212] ([209.85.219.212:63369] helo=mail-ew0-f212.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/98-03420-8892D2B4 for ; Sat, 19 Dec 2009 14:29:13 -0500 Received: by ewy4 with SMTP id 4so4334859ewy.12 for ; Sat, 19 Dec 2009 11:29:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=jYnhYZr774aSRiGFOwDF2vG20o6L2bJgA43GS1itxdg=; b=ZtjDzkQysQsVb98RXNAYECOF8NfNjqHoa+eVEZhlAxTrJDBghGJvYdR6+Vbnh1YDMB HcFKiAeSeiMcWG2nCz6HfABd+Yy1sD7BdUhUqLdJLMV6iJiXKyciDzczV8OtcPGJsmKk c8RdeMXnu+PvImCgJQyq2H9gSsRqto5kwFdyk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=otNfyUAKoMuLl2voSPuXLELYuqjcfgEabAKM0g33DwqBsp3rPS7Yyg82BtA9Wt6v+x qYYSPsR8SdDTBx/dhwyfGtbGQwG0EkKzfllE2XXPvYkunMxy45PEQaW4KxyyfSYh6jca 6SEKzEiSVdpwGn1rGpLcGPpbzHdzpdd1DUK1s= MIME-Version: 1.0 Received: by 10.216.162.142 with SMTP id y14mr2103626wek.192.1261250949209; Sat, 19 Dec 2009 11:29:09 -0800 (PST) In-Reply-To: <15.13.03420.1F8AC2B4@pb1.pair.com> References: <83.E2.63064.C512C2B4@pb1.pair.com> <1261183971.2756.1171.camel@guybrush> <15.13.03420.1F8AC2B4@pb1.pair.com> Date: Sat, 19 Dec 2009 11:29:09 -0800 Message-ID: To: Johannes Mueller Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] is_a() versus instanceof From: 0xcafefeed@gmail.com (mm w) class rootObject { ... function isMemberOrInstanceOfClass($object) { $className =3D is_object($object) ? get_class($object) : $o= bject; return ($this instanceof $className); } }; On Sat, Dec 19, 2009 at 2:20 AM, Johannes Mueller wrot= e: > Johannes "Schl=C3=BCter" wrote: >> >> On Sat, 2009-12-19 at 01:42 +0100, Johannes Mueller wrote: >>> >>> if($foo instanceof bar){ >>> .. >>> } >>> // runs without any notification >> >> instanceof is a language construct expecting a class identifier. >> It doesn't complain about on-existing classes as it would need to >> trigger the __autoloader which might be way too much. >> >>> and >>> >>> if(is_a($foo, bar)){ >>> .. >>> } >>> // runs with an undefined constant bar notification >> >> is_a() is a function expecting a string. And this warning is unrelated >> to the fact that the class "bar" doesn't exist, but due to the way PHP >> treats undefined constants. > > Thank you for your answers, that is what I've expected. Unfortunately thi= s > is sometimes annoying when using namespaces, where you have to take care = of > the namespaces too. > > I do understand the performance impact of a more complex solution and my > fault was to mix two different operations. I expected instanceof and is_a= () > to check if the class exists. > > My personal problem was, that I didn't recognized instanceof to treat the > requested class as a normal string, even it is not enclosed by quotation > marks. > > The only protective barrier in this case seems to be a skilled IDE, that > helps you to avoid referencing non existant classes. > > Cheers > Johannes > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >