Showing posts with label php-interview-questions-answers. Show all posts
Showing posts with label php-interview-questions-answers. Show all posts

Top PHP Interview Questions with Answers For Job

  What is PHP?     PHP is a server side scripting language  used for web development applications.     Php is the powerful tool for making dynamic website.     Many open source, free and commercial scripts    and   Stuff made by php  What is a data type? A Data type is the classification of data into a category according to its attributes; • Alphanumericcharacters...

find the number of parameters passed into function in PHP?

func_num_args() function returns the number of parameters/arguments passed to a function in PH...

difference between include and require?

Answer: It"s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt theexecution of the script. If the file is not found by include(), a warning will be issued, but execution willcontinu...

What is SQL Injection?

SQL Injection is the hacking technique which attempts to pass SQL commands (statements) through a web application for execution by the backend database. it can be prevented by mysql_real_escape_string() function of PHP. Such features as login pages, support and product request forms, feedback forms, search pages, shopping carts and the general delivery of dynamic content, shape modern websites and provide businesses with the means necessary to communicate with prospects and customers....

what is ob_start?

ob_start turns on output bufferin...

Scope Resolution Operator?

::  is the scope operator it is used to call methods of a class that has not been instantiated....

What is MVC?

MVC- Model, View, Controller - is simply Model -  contains data access code and all of you business logic code. View - Contains markup/design code, generally html,xml, json. Controller -  contains very little code, just whatever is needed to call the Model code and render the View code....

how access a method in the parent class that's been overridden in the child?

Prefix parent:: to the method name: class shape { function draw( ) { // write to screen } } class circle extends shape { function draw($origin, $radius) { // validate data if ($radius > 0) { parent::draw( ); return true; } return false; } ...

how execute different code depending on the number and type of arguments passed to a method?

PHP doesn't support method polymorphism as a built-in feature. However, you can emulate it using various type-checking functions. The following combine( ) function uses is_numeric(), is_string(), is_array(), and is_bool(): // combine() adds numbers, concatenates strings, merges arrays, // and ANDs bitwise and boolean arguments function combine($a, $b) { if (is_numeric($a) && is_numeric($b)) { return $a + $b; } if (is_string($a) && is_string($b)) { return "$a$b"; } if (is_array($a) ...

want to link two objects, so when you update one, you also update the other?

Use =& to assign one object to another by reference: $adam = new user; $dave =& $adam...

how eliminate an object?

Objects are automatically destroyed when a script terminates. To force the destruction of an object, use unset( ): $car = new car; // buy new car ... unset($car); // car wrec...

how create a new instance of an object?

Define the class, then use new to create an instance of the class: class user { function load_info($username) { // load profile from database } } $user = new user; $user->load_info($_REQUEST['username'])...

exchange the values in two variables without using additional variables for storage?

To swap $a and $b: list($a,$b) = array($b,$a)...

access the values passed to a function?how

Use the names from the function prototype: function commercial_sponsorship($letter, $number) { print "This episode of Sesame Street is brought to you by "; print "the letter $letter and number $number.\n"; } commercial_sponsorship('G', 3); commercial_sponsorship($another_letter, $another_number)...

how associate multiple elements with a single key?

Store the multiple elements in an array: $fruits = array('red' => array('strawberry','apple'), 'yellow' => array('banana')); Or, use an object: while ($obj = mysql_fetch_object($r)) { $fruits[ ] = $obj; ...

How to check whether two floating-point numbers are equal?

Use a small delta value, and check if the numbers are equal within that delta: $delta = 0.00001; $a = 1.00000001; $b = 1.00000000; if (abs($a - $b) < $delta) { /* $a and $b are equal */ ...

You want to extract part of a string, starting at a particular place in the string

Use substr( ) to select your substrings: $substring = substr($string,$start,$length); $username = substr($_REQUEST['username'],0,8)...

Php get_meta_tags-Extracts all meta tag content attributes

get_meta_tags — Extracts all meta tag content attributes from a file and returns an array <?php// Assuming the above tags are at www.example.com$tags = get_meta_tags('http://www.example.com/');// Notice how the keys are all lowercase now, and// how . was replaced by _ in the key.echo $tags['author'];       // nameecho $tags['keywords'];  &nbs...

PHP Redirect - Redirect Script?

PHP Redirect Function header('Location: destination.php'); exit();   ou need the Location: part so the browser knows what header it's  receiving. Also, don't forget to  do an exit() or die() right after the redirect.  ...

Control Structures

if else elseif/else if Alternative syntax for control structures while do-while for foreach break continue switch declare return require include require_ once include_ once goto...