Article View: pl.comp.lang.php
Article #219858referencja jako parametr
From: smerf
Date: Sat, 25 Jul 2009 15:08
Date: Sat, 25 Jul 2009 15:08
32 lines
1201 bytes
1201 bytes
<?
ini_set('display_errors', '1');
error_reporting(E_ALL);
class Klasa {
public function funkcja ($a, &$b) {
$a = 'a1';
$b = 'b1';
}
}
$a = '';
$b = '';
$ob = new Klasa();
$ob->funkcja($a, &$b);
echo $a;
echo $b;
?>
output:
b1
Taki sam rezultat gdy:
- usuniemy ampersand z wywolania fcji tj. $ob->funkcja($a, $b);,
- usuniemy ampersand z deklaracji fcji tj. public function funkcja ($a, $b) { }
Jak jest wiec poprawnie? Jak powinno sie pisac?
Moim zdaniem ampersand w deklaracji i wywolaniu jest najczytelniej.
Technical Details
Message-ID:
<4a6b2012$1@news.home.net.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!news.home.net.pl!not-for-mailShow Full Headers
Complete Article Headers
Date: Sat, 25 Jul 2009 17:08:05 +0200 From: smerf <smerf@akcesoria.home.pl> User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 Newsgroups: pl.comp.lang.php Subject: referencja jako parametr NNTP-Posting-Host: 79.186.106.7 Message-ID: <4a6b2012$1@news.home.net.pl> X-Trace: news.home.net.pl 1248534546 79.186.106.7 (25 Jul 2009 17:09:06 +0200) Organization: home.pl news server Lines: 32 X-Authenticated-User: smerf@akcesoria.home.pl Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!news.home.net.pl!not-for-mail Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit