Skip to main content
added 56 characters in body
Source Link
Sampson
  • 268.8k
  • 76
  • 546
  • 570

I am having trouble with naming the function. I have a class and I need 2 functions something like below.

class myclass{ public function tempclass() { echo "default";
}

public function tempclass($text) { echo $text; } }

class myclass { public function tempclass () { echo "default"; } public function tempclass ( $text ) { echo $text; } } 

When I call

tempclass('testing'); //(called after creating the object)

tempclass('testing'); // ( called after creating the object ) 

function tempclass()function tempclass() is being called how can i have 2 functions with same name but different parameters?

I am having trouble with naming the function. I have a class and I need 2 functions something like below.

class myclass{ public function tempclass() { echo "default";
}

public function tempclass($text) { echo $text; } }

When I call

tempclass('testing'); //(called after creating the object)

function tempclass() is being called how can i have 2 functions with same name but different parameters?

I am having trouble with naming the function. I have a class and I need 2 functions something like below.

class myclass { public function tempclass () { echo "default"; } public function tempclass ( $text ) { echo $text; } } 

When I call

tempclass('testing'); // ( called after creating the object ) 

function tempclass() is being called how can i have 2 functions with same name but different parameters?

Source Link
Abhishek Salian
  • 934
  • 2
  • 10
  • 27

PHP class function naming

I am having trouble with naming the function. I have a class and I need 2 functions something like below.

class myclass{ public function tempclass() { echo "default";
}

public function tempclass($text) { echo $text; } }

When I call

tempclass('testing'); //(called after creating the object)

function tempclass() is being called how can i have 2 functions with same name but different parameters?