Php oop!

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

31 replies · 1,854 views · started 14 years ago · 1 min read

11 participants
asifnayem Developer · 119 posts #1

can any one give a firm details about whats the difference between normal php and php oop!! what is extra in object oriented programming!! please let me know. I came here as i googled this and not getting the whole thing.

just_m3. Developer · 199 posts #2

asifnayem wrote: can any one give a firm details about whats the difference between normal php and php oop!! what is extra in object oriented programming!! please let me know. I came here as i googled this and not getting the whole thing.

🙂 Here an simple description of what php oop can' do .. i can't tell you more because i'm still learning on that 😀

So . php oop its gonna make your codding very,very light and easy to manage .. because an php oop class can be used on manny scripts on different tasks is adaptable so for example to make an ease off ussage you could use it verry simple such as

<?php 

$myoop= new oopclass();
$myoop->task('commands here','and something else');

 ?>

While you gonna still learning you gonna think that its more like some' simple functions defined , but believe me that its more than just a simple function because an' oop class can use lot of functions defined in his content , as you can see in the upper example $myoop->task is a called function so you can execute a whole script just with 3 - 4 lines as simple as that 😛

So go for OOP ... 🙂

Object Oriented PHP Tutorial for Beginners - KillerPHP.com

here is a beginner tutorial for you 😊 enjoy reading it !

Cheers !

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

morse Senior · 364 posts #3

For large applications, PHP OOP is good but for small applications PHP OOP is bad

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

shushant Developer · 207 posts #4

Any1 of u Can Tell me that is dis right way to access functions in class

class mycls {
public function me(){
return "Hi";
}
public function hehe(){
echo $this->me();
}
}

or this

class mycls {
public function me(){
return "Hi";
}
public function hehe(){
echo me();
}
}

nd what is use of $this

softwarefreak Senior · 349 posts #5

1st one is correct

$this represents the object inside the class

class mycls {
public $name;
public function me()
{
return "Hi";
}
public function hehe()
{
//inside the class
echo $this->me(); 
}
}
$object = new mycls;
echo $object->me();
//look at the above code, you had to create an instance of the class but inside the class you can use $this :P :D

😎

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

shushant Developer · 207 posts #6

softwarefreak wrote: 1st one is correct

$this represents the object inside the class

class mycls {
public $name;
public function me()
{
return "Hi";
}
public function hehe()
{
//inside the class
echo $this->me(); 
}
}
$object = new mycls;
echo $object->me();
//look at the above code, you had to create an instance of the class but inside the class you can use $this :P :D

😎

😛 i know had to create an instance make it wrk 🙂

softwarefreak Senior · 349 posts #7

shushant wrote: :P i know had to create an instance make it wrk :)

I know dat, you know but I tried to show the use of $this 🙂 😁 📖 oreilly OOP e-book for a clear understanding, it's very helpful

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

shushant Developer · 207 posts #8

softwarefreak wrote: I know dat, you know but I tried to show the use of $this 🙂 😁 📖 oreilly OOP e-book for a clear understanding, it's very helpful

Don't take me as wrng i was in need of help In OOP 😛 Having Problem understaning The use of $this and Some other Variables

StunningNick Junior · 40 posts #10

$this

softwarefreak wrote: 1st one is correct

$this represents the object inside the class

class mycls {
public $name;
public function me()
{
return "Hi";
}
public function hehe()
{
//inside the class
echo $this->me(); 
}
}
$object = new mycls;
echo $object->me();
//look at the above code, you had to create an instance of the class but inside the class you can use $this :P :D

😎

i think "$this" represent non-static call , don't get me wrong, I'm an noob willing to learn 😛

Don't think i am bad , i used to be too good one time...

softwarefreak Senior · 349 posts #11

StunningNick wrote: i think "$this" represent non-static call , don't get me wrong, I'm an noob willing to learn :P

Ok master, got it 😀

added after couple of minutes 😀 (just phped php.net for perfect answer)

$this is a reference to the calling object (usually the object to which the method belongs, but possibly another object

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

StunningNick Junior · 40 posts #12

this

softwarefreak wrote: $this represents the object inside the class i think "$this" represent non-static call , don't get me wrong, I'm an noob willing to learn :P

none of us is wrong technically/programatically...

"this" represent an non-static call to an object/method/variable bla bla bla etc... thanks for correction Dude :cheers:

Don't think i am bad , i used to be too good one time...

something else Fellow · 2,296 posts #13

im a noob at oop ..... how do you call for a function within a function within the same class ?

something else Fellow · 2,296 posts #15

I mean if i have got a class like:

<? 
class someclass{

funtion function1(){
 //do something here
}

funtion function2(){
  //how do i use function1 here?
// $someclass->function1();  //tried this and it caused errors
// or is it $this->function1(); //i havent tried using this
}

}
?>
antony2kx Developer · 94 posts #16

example OOP wapcreate.com is pure OOP and is built upon MVC architecture

class Car {

private $carname;
private $caryear;
public object;

public function __construct($carname, $caryear)
{
   self::setName($carname); //this could also be done using $this->setName($carname) or Car::setName($carname)
   self::setYear($caryear);
}

public function setYear($y)
{
   $this->caryear = $y;
}

public function setName($n)
{
   $this->carname = $n;
}

public function getName()
{
   return $this->carname;
}

public function getYear()
{
  return $this->caryear;
}

}; // the semicolon is not needed here

usage of this class will be 

$car = new Car("Lamboginy", "2010");

you can now use the get methods to access properties of this class

like if you wanted to print the year of the car it will be like

echo $car->getYear(); will print 2010;

you can also have objects within other objects like 

$car->object = new Car("BMW", "2011");

echo $car->object->getName(); will print BMW
GumSlone Administrator Principal · 1,690 posts #17
<? 
class someclass{

function function1(){
 //do something here
}

function function2(){

$this->function1();
}

}
?>

or outside

$c = new someclass;
$c->function1();
$c->function2();

call function3 in a class which is not inside the class:

<? 
function function3()
{
return 'do something';
}

class someclass{

function function1(){
 //do something here
}

function function2(){
$something_inside = $this->function1();
$something_outside = function3();
}

}
?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

something else Fellow · 2,296 posts #18

im guessing if you have got 2 classes then to use a function from the second class in the first class function you would use the same method as calling it outside the class? eg:

<?
class someclass{

function function1(){
$c = new someclass2; 
$c->function2();
}

}

class someclass2{

funtion function2(){

}

}
?>
antony2kx Developer · 94 posts #19

That is one way at something else

or you can do it by extending the first class by the second one

for example

class Class1{

public function functionInClassOne()
{
echo "hello worlds";
}

}

class Class2 extends Class1{

public function printHelloWorld()
{
   $this->functionInClassOne(); //this will use the methods in class 1 because u have extended it
}

}

so instance would be 

$instance = new Class2;

$instance->printHelloWorld();

as easy as it gets

something else Fellow · 2,296 posts #20

what im a little confused about when using oop it makes your script a lot longer does this make it longer to process?

Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close