Solved

echo type is name

Posted on 2013-12-11
5
301 Views
Last Modified: 2013-12-24
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
Comment
Question by:rgb192
5 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39712556
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39712565
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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39713897
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
 
LVL 34

Accepted Solution

by:
Slick812 earned 500 total points
ID: 39717673
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
 

Author Closing Comment

by:rgb192
ID: 39737823
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question