Hi,
I'm learning OOP and I'm having issue echoing an attribute
function.
This is my example:
<?php
class sandwich
{
function sandwich($hero)
{
echo "I like to eat $hero sandwich.<br>";
}
}
$a = new sandwich("roast beef");
$b = new sandwich("pastrami");
$c = new sandwich("turkey");
?>
When I echo it out:
I like to eat roast beef sandwich.
I like to eat pastrami sandwich.
I like to eat turkey sandwich.
Here is my attribute function
with the same format:
<?php
class sandwich
{
var $attribute;
function operation($hero)
{
$this->attribute = $hero;
echo $this->attribute;
}
}
$a = new sandwich("roast beef");
$b = new sandwich("pastrami");
$c = new sandwich("turkey");
?>
When I echo it out it went blank? There's no error at all.
I want to know how the attribute function
looks like and how works.
Any Suggestions and explanation will help. I appreciate it. Thanks!