Trouble Learning Passing By Reference - Error Being Produced

Discussion in 'PHP' started by anthony parsons, Jun 10, 2010.

  1. #1
    Hi,

    I am learning PHP from PHP, MySQL & Javascript, Robin Nixon 2009, though I have hit a snag at Passing by Reference stage in the book, which says it should produce x, but is producing an error instead. The example given is:

    $a1 = "WILLIAM";
    $a2 = "henry";
    $a3 = "gatES";
    
    echo $a1 . " " . $a2 . " " . $a3 . "<br />";
    fix_names($a1, $a2, $a3);
    echo $a1 . " " . $a2 . " " . $a3;
    
    function fix_names(&$n1, &$n2, &$n3)
    {
    	$n1 = (ucfirst(strtolower($n1));
    	$n2 = (ucfirst(strtolower($n2));
    	$n3 = (ucfirst(strtolower($n3));
    }
    PHP:
    Now, I am doing this on my localhost WAMP, which is running:

    PHP 5.2.11
    Apache 2.2.14

    I installed this onto my actual hosted server, still error.

    Now, am I correct then that this book is stupidly saying I should get a result from the echo commands, when instead this must be parsed at an include to another file? My limited interpretation is that this is what passing by reference is all about!

    Whilst it says the output should be the before, then after, being convert to lowercase then capitalise, I can see that maybe I am ahead of myself at the same point as I haven't learnt about includes yet... so I am guessing that the book is technically wrong and shouldn't echo anything without being called to another file.

     
    anthony parsons, Jun 10, 2010 IP
  2. anthony parsons

    anthony parsons Well-Known Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #2
    Disregard... worked it out... the extra bracket I included at the start of ucfirst. Ok... new lesson, fault finding.
     
    anthony parsons, Jun 10, 2010 IP