Solved

echo type is name

Posted on 2013-12-11
5
295 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 30

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 30

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 108

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 33

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now