6. Parameters and Arguments


#1

https://www.codecademy.com/en/courses/web-beginner-en-RcIEe/0/6?curriculum_id=5124ef4c78d510dd89003eb8


It lets me continue, however it echoes this error:

Use of undefined constant Cole - assumed 'Cole' (line 11)Greetings, Cole!

Just wondering what's wrong/ why it lets me continue, Thanks!


<html>
	<head>
		<title></title>
	</head>
	<body>
      <p>
        <?php
        function greetings($name){
            echo "Greetings, "  . $name . "!";}
            
            greetings(Cole);
        ?>
      </p>
    </body>
</html>


#2

@colebarrass
In your greetings() function call you are using an argument Cole

The interpreter will try to evaluate Cole as if it were a variable
the interpreter than run's into an error-situation as you have NOT pre-defined a variable Cole
and for your mercy will assume you used a string-Value 'Cole'
and it is even mentioned to you
Use of undefined constant Cole - assumed 'Cole' (line 11)Greetings, Cole!


#3

When I called the greetings function like greetings("Cole") it came out normally on the other screen, is it still technically wrong?


#4

@colebarrass,
It is all correct.... it is the essence of using a function

Function Talk

With

function greetings($name){
         /* Being of the FUNCTION-BODY
            PARAMETER $name is used as a =local= VARIABLE
            the =local= $name VARIABLE will get its VALUE 
            as you =call= the greetings() function
            using 1 ARGUMENT in this case the =string= Value "Cole"
         */
                  echo "Greetings, "  . $name . "!";
              }

you have defined a greetings() function which takes 1 parameter $name

As you call / execute the greetings function
greetings();
and the greetings() function was defined as having 1 parameter
you will have to provide 1 argument in this case the string Value "Cole"
greetings("Cole");

some quotes from the outer-world:

argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block

OR

"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".