Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

echo type is name

http://mobile.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28314431.html

What is type in echotype?  Is it a name? And i think calling a method that displays echo is confusing. Sorry just trying to understand code better.
0
rgb192
Asked:
rgb192
1 Solution
 
Marco GasiFreelancerCommented:
echoType is simply the name Ray assigned to a function which prints the type of the class.
But there is no statement which sets the type so if you use that class an call that method I think you'll get an empty string.
0
 
Marco GasiFreelancerCommented:
But son't misunderstand me: Ray provided that code only to show " how to call the methods", taht is that code is a teaching code but not working code...
0
 
Ray PaseurCommented:
calling a method that displays echo is confusing
I agree.  I think the fewer echo or print statements you have, the better.  I also think that the fewer in-and-out of PHP structures, the better.

You can name a variable or function anything you want.  It could have been named "pigwhistle" and that would have been OK to PHP, but would violate Antipractice #8.  A frequent construct in object creation are "setters" and "getters" that allow access to protected or private properties.  For example, a class that describes a product might have setters and getters for the size and color.  These might be (logically) named "getSize()" and "setSize()" , etc.  Since you can use "getSize()" to retrieve the size information that would seem to be enough; you would not have any practical need for a method that was "echoSize()."
0
 
Slick812Commented:
More Questions from  rgb192 ? ? As I asked in that question-
I really have no Idea what you are suppose to be learning from this tutorial example? ?
The code you present at the top of the page in your Question has this -

class Vegetable{public $type='type';
public function echoType(){echo $this->type;}
}

Since I have NO IDEA of what was being taught in your Class tutorial about interface and extensions, I added completely meaningless properties and methods to your totally empty
class Vegetable {}

the $type  was just my first thought for "TYPE OF VEGETABLE" as carrot, cabbage, bean

and since I had a property of $type and wanted some to have at least one Class method I wrote -
public function echoType(){echo $this->type;}

and what you have failed to see in this, I will try to explain -
In a Class you can place ANY functions (and in a Class the function is called a method) with -
public function
// You have to use the PHP word "function" for this you can not use method

and name that "function-method"  any name that you want to type in, I just happened to type the function-name as "echoType", because that is what the method does , it echos the property - $this->type;

But I really was NOT sure about what to try to teach you with this code, since you never said what all of this tutorial code was for.
and I apologize for - "And i think calling a method that displays echo is confusing", , but the code I added as -
public $type='type';
public function echoType(){echo $this->type;}

did NOT have any instructional - teaching goal for you, I could have had code -
class Vegetable{public $color='green';
public function displayColor(){echo 'Vegetable Color is '.$this->color;}
}

with user code as -
$pep = new Pepper;
$pep->displayColor();// displayColor() from the PARENT CLASS of Pepper

I could have named the method displayColor()  as  color()   OR   showColor()   OR  anything else, so may be this helps to explain some of that  class Vegetable  code

I was not aware that you would think that the method  echotype() and the property $type would have some special meaning, they do not, , sorrory about that, my bad.


= = = = = = = = = =
I will give you some of my opinion about studying the Class interface , I do not believe that it is useful for beginners in PHP Classes, and is mostly used for a Team of several coders to have compatible, many different Classes that are using the same methods by passing an interface definition between All of the team coders.
However there are some very useful  "Predefined Interfaces and Classes" that are helpful to use, but Class beginners may not understand them very well, , ,  you can see them at -
http://www.php.net/manual/en/reserved.interfaces.php
0
 
rgb192Author Commented:
I just happened to type the function-name as "echoType", because that is what the method does , it echos the property - $this->type;

I was not aware that you would think that the method  echotype() and the property $type would have some special meaning, they do not, , sorrory about that, my bad.

And extra information about interfaces

I will give you some of my opinion about studying the Class interface , I do not believe that it is useful for beginners in PHP Classes, and is mostly used for a Team of several coders to have compatible, many different Classes that are using the same methods by passing an interface definition between All of the team coders.


I was told not to use this oop php tutorial and now I am reading another book (which has no oop in the first 100 pages)

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now