Showing posts with label oops. Show all posts
Showing posts with label oops. Show all posts

Tuesday, April 6, 2010

How will you check whether a class already defined or not?

Answer

Php has built-in function to check whether a class exists or not

The function is

class_exists()

Monday, April 5, 2010

How to create a class in php

Answer

To create a class we need to use a class keyword.

Example

class Phpinterview{

}

?>

The above created a class named Phpinterview.

To add a method to a class follow this

class Phpinterview{

function questions{

echo 'php questions';
}
function answers{
echo 'Answers for the questions';
}

}

?>

Here you have created two methods questions and answers for the class Phpinterview

Thursday, April 1, 2010

Identifying the number of parameters passed to a function?

Answer:

We can use - func_num_args()

This function can return the number of argument passed to the function

small example

function test()
{
$numargs = func_num_args();
echo
"Number of passed arguments: $numargs\n";
}

test(1, 2, 3);

Output
======
Number of passed arguments: 3