Thursday, July 30, 2015

About PHP

The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. This tutorial helps you to build your base with PHP.

Audience

This tutorial is designed for PHP programmers who are completely unaware of PHP concepts but they have basic understanding on computer programming.

Prerequisites

Before proceeding with this tutorial you should have at least basic understanding of computer programming, Internet, Database, and MySQL etc is very helpful.

Execute PHP Online

For most of the examples given in this tutorial you will find Try it an option, so just make use of this option to execute your PHP programs at the spot and enjoy your learning.
Try following example using Try it option available at the top right corner of the below sample code box −
<html>
   <head>
      <title>Online PHP Script Execution</title>      
   </head>
   
   <body>
      
      <?php
         echo "<h1>Hello, PHP!</h1>";
      ?>
   
   </body>
</html>

OOPS Concepts Test Questions




A polymorphism can be called what?
  • A relationship between two objects.
  • The order of objects in a sequence.
  • A function that performs in different ways.
  • Functions that perform the same way.
Answer: A function that performs in different ways.
How can dynamic binding be contrasted with static binding?
  • They are bound together with polymorphic compiling.
  • Dynamic binding is compile time binding, while static binding is runtime binding.
  • Static binding is better than dynamic binding.
  • Dynamic binding is runtime binding, while static binding is compile time binding.
Answer: Dynamic binding is runtime binding, while static binding is compile time binding.
What is a simple way to think of inheritance?
  • One object generating another object.
  • One object acquiring the properties of another.
  • One object writing new properties for another.
  • New properties written from scratch.
Answer: One object acquiring the properties of another.
When does binding occur with static binding?
  • At runtime.
  • Never.
  • At compile time.
  • After runtime binding occurs.
Answer: At compile time.
A clone method is needed to:
  • make any copies of the parent object
  • make any copies of children objects
  • to create a second copy of all contained subobjects
  • make any copies of this object
Answer: to create a second copy of all contained subobjects
What are classes used for?
  • Classes are used to manage metadata.
  • Classes define objects.
  • Classes are used to define specific types.
  • Classes describe different features.
Answer: Classes are used to define specific types.
Programming languages supporting the OOPS paradigm are typically contained within what two classes?
  • Logic-based and inference-based.
  • Prototype-based, or class-based.
  • System based and program-based.
  • OOPS-based and object-based
Answer: Prototype-based, or class-based.
When two methods have the same name, what are they considered, and what kind of binding do they have?
  • Overloaded, static.
  • Overloaded, late.
  • Overloaded, dynamic.
  • Overhauled, static.
Answer: Overloaded, static.


What is a primary motivation for using OOP?
  • To increase speed of writing code.
  • To increase reusability and maintainability of code.
  • To increase data coupling.
  • Because other programming paradigms have become obsolete.
Answer: To increase reusability and maintainability of code.
Ref counts are:
  • a way of managing object lifetimes
  • how wrestling referees determine a winner
  • magic methods on all classes
  • an optimization for compilers
Answer: a way of managing object lifetimes
When a variable is defined within a class, what is it considered?
  • A varying variable.
  • An early variable.
  • A class variable.
  • An instance variable.
Answer: An instance variable.
Why is dynamic binding referred to as “late binding”?
  • It is not bound at compile time.
  • It is bound at compile time.
  • It is not bound at runtime.
  • It is never bound.
Answer: It is not bound at compile time.





Static functions can use which variables?
  • private and static
  • public
  • private
  • static
Answer: static
What are objects identified by?
  • Their qualities.
  • Their relationship with other objects.
  • Their orientation within a program.
  • Their unique name.
Answer: Their unique name.
Which of the following could be considered a polymorphism?
  • Two classes named “clsCalculation” with the single function, “add”.
  • Two functions named “clsCalculation”.
  • The class, “clsCalculation” with two functions, both named “Add”.
  • Two classes named “add”.
Answer: The class, “clsCalculation” with two functions, both named “Add”.
Can an object have more than one instance?
  • Yes.+58pts
  • No.
  • Yes, but they must be in two different physical locations.
  • Yes, but it will result in errors.
Answer: Yes





A mutator method is also known as a:
  • Setter
  • deleter
  • updater
  • getter
Answer: Setter
True or false? Static variables are visible outside of the class
  • depends
  • False
  • True
Answer: depends
An abstract class can:
  • Be subclassed
  • Only contain abstract methods
  • Be instantiated
Answer: Be subclassed
A trait is:
  • another word for class
  • another word for interface
  • a collection of methods
Answer: a collection of methods








What is the difference between interfaces and abstract classes?
  • interfaces cannot have methods whereas abstract classes can
  • interfaces cannot have properties whereas abstract classes can
  • abstract classes can provide default implementation whereas interfaces cannot provide implementations
  • interfaces can provide default implementation whereas abstract classes cannot provide implementations
Answer: abstract classes can provide default implementation whereas interfaces cannot provide implementations
Why is composition considered a simpler method than inheritance?
  • It isn't considered a simpler method.
  • Composition has complex namespace clashes.
  • It is filled with complicated inheritance hierarchies.
  • Composition lacks the namespace clash, and the complicated inheritance hierarchies.
Answer: Composition lacks the namespace clash, and the complicated inheritance hierarchies.
True or false? Abstract methods are only defined in the parent.
  • False
  • True
Answer: False
True or false? Polymorphism means to support multiple inheritance.
  • True
  • False
Answer: False



What is the most important trait of a polymorphism?
  • The common interface.
  • The total differences.
  • The multiple interfaces.
  • The difference in interface.
Answer: The common interface.
True or false? It's legal to have two variables both named $count where one is a global variable and the other is used inside a class.
  • only if $count is static in both uses
  • False
  • True
Answer: True
What are method names typically restricted by?
  • Code conventions.
  • The alphabet.
  • Grammatical rules.
  • Ethical rules.
Answer: Code conventions.
Which of the following is included in the field of formal semantics?
  • The comprehension of relational models.
  • The definition of semantic models.
  • The understanding of programming models.
  • The definition of logistic models.
Answer: The definition of semantic models.




What kind of relationship is the public class “Animal” with the extension, “Mammal” demonstrating?
  • HAS-A Relationship
  • IS-A Relationship
  • WAS-A Relationship
  • IS-NOT-A Relationship
Answer: IS-A Relationship
Lambda functions are allowed in class definitions
  • False
  • True
Answer: False














JQuery Test Questions For Elance



What method is used to switch between adding/removing one or more classes (for CSS) from selected elements?
  • toggleClass()
  • switch()
  • switchClass()
  • classSwitch()
Answer: toggleClass()
What keyword would you use to refer to the object on which the currently executing method has been invoked?
  • that
  • object
  • this
  • here
  • medium
Answer: this
Which sign does jQuery use as a shortcut for jQuery?
  • the $ sign
  • the . sign
  • the > sign
  • the # sign
Answer: the $ sign





What does the empty() function do?
  • Clears the text in a node
  • Removes all child nodes of the set of matched elements from the DOM including the parent node
  • Checks if a node is empty
  • Removes all child nodes of the set of matched elements from the DOM
Answer: Removes all child nodes of the set of matched elements from the DOM
<div id="MyDiv">Two</div> <div id="MyDiv">One</div> <div id="MyDiv">Five</div> Given the above HTML What would the output of the following code be? var myDivText = $('#MyDiv').text() console.log(myDivText)
  • Undefined
  • Null
  • Two
  • One
  • Five
Answer: Two

Which function does jQuery provide to remove whitespace from the beginning and end of a string?
  • $.stripspace( )
  • $.trim( )
  • $.strip( )
  • jQuery does not provide such function.
Answer: $.trim( )



What is the output of the following: $.each([1,2,3], function(){ document.write(this + 1); });
  • 223
  • 1231
  • "234"
  • undefined
Answer: "234"
What is true of the following code? $('<img>', { src: 'images/little.bear.png', alt: 'Little Bear', title:'I woof in your general direction', click: function(){ alert($(this).attr('title')); } })
  • It will alert "title"
  • It will alert the name of the element being clicked
  • It will alert the value of title attribute of the image being clicked
  • It will alert attribute title
Answer: It will alert the value of title attribute of the image being clicked
For best performance in modern browsers, which of the following would you use to select all radio inputs?
  • $('[type="radio"]');
  • $('[input.radio]');
  • $('[input="radio"]');-21pts
  • $('||radio');
  • $('.radio');
Answer: $('[type="radio"]');




When an event is triggered on an element, the same event is also triggered on all of that element’s ancestors. What is the name of this process?
  • medium
  • event bubbling
  • upward progress
  • progressive enhancement-23pts
  • global event
Answer: event bubbling
What method checks for the presence of a class before applying or removing it?
  • .apply_remove()
  • medium
  • .checkPresence()
  • .checkFunction()
  • .toggleClass()
Answer: .toggleClass()
Which selector will only return one element?
  • :nth-child()+40pts
  • :one-based()
  • :even
  • :odd
Answer: nth-child()





What is the equivalent of the following code? $('div').click(function {alert(1);});
  • $('div').call('click',function {alert(1);});
  • $('div').bind('click',function {alert(1);});
  • $('div').handler('click',function {alert(1);});
  • $('div').event('click',function {alert(1);});
Answer: $('div').bind('click',function {alert(1);});
What term refers to the acceleration and deceleration that occurs during an animation?
  • gradient
  • speeding
  • velocity
  • resizing
  • easing
Answer: easing
What does the following code do? $(".foobar").find(".foo").fadeOut();
  • Fade out of all descendants of elements matching ".foo" inside those matching ".foobar"-30pts
  • Fade out of elements matching ".foobar"
  • Fade out of elements matching ".foo" that are descendants of elements matching ".foobar"
  • Fade out of all children of elements matching ".foobar"
Answer: Fade out of elements matching ".foo" that are descendants of elements matching ".foobar"




Which custom selector is case sensitive?
  • :contains()
  • :includes()
  • medium
  • :case()
  • :custom()
Answer: :contains()
True or False? jQuery UI is part of jQuery.
  • True
  • False
Answer: False
<p>Hello</p> $('p').prepend('world '); $('p').append('.'); p = ?
  • world Hello.
  • Helloworld .
  • .world Hello
Answer: world Hello.
$.foo() is equivalent to:
  • javascript.foo()
  • document.foo()
  • None of them
  • jQuery.foo()
Answer: jQuery.foo()







What is '$();' equivalent to?
  • operator();
  • java();
  • Function();
  • function();
  • jQuery();
Answer: jQuery();
Which is a class selector?
  • $('.name')
  • $('#name')
  • $('_name')
Answer: $('.name')
What language is jQuery written in?
  • CSS
  • Java
  • JavaScript
  • PHP
Answer: JavaScript
What does this script do? $(function() { $( "#effect" ).animate({ backgroundColor: "#fff" }, 1000 ); });
  • Changes the background color of the element with id 'effect' to #fff within 1 second.
  • Changes the background color of the element with class 'effect' to #fff within 1 second.
Answer: Changes the background color of the element with id 'effect' to #fff within 1 second.



Which of the following is correct?
  • jQuery is a JSON Library
  • None of these
  • jQuery is a JavaScript Library
Answer: jQuery is a JavaScript Library
Illustrate the code needed to include the jQuery library in an HTML file:
  • $(script) src="jQuery.js")
  • $(script src)="jQuery.js"(/script)
  • <script src="jQuery.js"></script>
  • $script src="jQuery.js"
Answer: <script src="jQuery.js"></script>
What do selectors do?
  • Allows the content to be stopped at some point.
  • Allows you to select HTML elements (or groups of elements) by element name, attribute name or by content.+6pts
  • Allows selection of libraries.
  • Allows you to select an array in the node list.
Answer: Allows you to select HTML elements (or groups of elements) by element name, attribute name or by content.

Which is NOT a jQuery method?
  • show()
  • fadeIn()
  • toggle()
  • alias()
Answer: alias()



In the following statement, which is the selector? $('p').css('color','blue');
  • .css
  • p
  • blue
  • color
Answer: p
Which of the following is used to schedule a function to execute after an animation has completed?
  • AJAX
  • graceful degradation
  • progressive enhancement
  • callback function
  • chaining
Answer: callback function
What does the following return? $.inArray("foo", ["foo", "bar"]);
  • true
  • 0
  • TRUE
  • 1
Answer: 0
How would you prevent the default browser action from an event handler without affecting other properties of the event flow?
  • $a.click(function () { /* code */ return false; });
  • $a.click(false);
  • $a.click(function (e) { /* code */ e.returnValue = false; });
  • $a.click(function (e) { /* code */ e.preventDefault(); });
Answer: $a.click(function (e) { /* code */ e.preventDefault(); });

Which method is used to bind an event handler to existing and future matching elements?
  • attach();
  • click();
  • .on();
Answer: .on();
You can copy an element by calling which of the following methods?
  • cloneTo()
  • copy()
  • moveTo()
  • clone()
Answer: clone()
What is the proper way to show an element?
  • $('#foo').style('show');
  • $('#foo').show();
  • $('#foo').display('show');
  • $('#foo').showElement();
Answer:$('#foo').show();
Which of these is NOT a valid way to initiate the document.ready call?
  • jQuery(document).ready(function($) { /* Stuff here */ })(jQuery);
  • $(document).ready(function() { /* Stuff here */ });
  • $(function() { /* Stuff here */ });
  • (function(x) { x(function() { /* Stuff here */ }); })(jQuery);
Answer: jQuery(document).ready(function($) { /* Stuff here */ })(jQuery);





What language is jQuery constructed in?
  • C++
  • Java
  • PHP
  • JavaScript
Answer: JavaScript
You can animate 'color' and 'background-color' properties.
  • False
  • True
Answer: False

How is jQuery licensed?
  • Proprietary
  • Open source
  • Secret
  • Private
Answer: Open source
What is $(fn); a shortcut for?
  • $(window).on('load', fn);
  • $( fn() ); // Shortcut to create or select elements using the string returned by the "fn" function.
  • $(document).ready(fn);
Answer: $(document).ready(fn);





Which of the following syntaxes are equivalent to $(document).ready(handler)?
  • .ready()
  • All of these
  • .load()
  • $(handler)
Answer: $(handler)
How do I pull a native DOM element from a jQuery object?
  • $("#foo[0]");
  • $( "#foo" ).get( 0 );
  • $( "#foo" ).get(native[ 0 ]);
  • $( "#foo" ).find(native[ 0 ]);
Answer: $( "#foo" ).get( 0 );
What does the following code do: $('#myDiv').trigger('click');
  • When a click occurs the trigger is going to be activated.
  • It makes a click on any element and creates a trigger.
  • It sets up a trigger. When a click occurs, the trigger is going to be activated.
  • It simulates a click on the element and runs all the event handlers associated with it.
Answer: It simulates a click on the element and runs all the event handlers associated with it.

What does $('#myDiv').load('page.html') do?
  • it loads the #myDiv on the contents of the 'page.html' browser
  • it fires an AJAX request, fetches the result of page.html as text, and inserts it into the div
  • It adds the string 'page.html' as the contents of the #myDiv div.
Answer: it fires an AJAX request, fetches the result of page.html as text, and inserts it into the div
The selector :disabled will perform the following:
  • None of the above
  • Select only elements in a disabled state
  • Disable any elements currently set to an enabled state
  • Create a new element with the state set to disabled
Answer: Select only elements in a disabled state
What does the $.get() jQuery function do?
  • It fires a GET OBJECT request
  • It fires a GET AJAX request
  • It returns the DOM elements that are contained in the jQuery object.
  • It returns an object
Answer: It fires a GET AJAX request
How do you clear the contents of this paragraph element? <div id='file'><p>content goes here</p></div>
  • $("file").clear();
  • $("#p").empty()
  • $('#file p').empty();
  • $(".file").empty();
  • $("#file").clear();
Answer: $('#file p').empty();

Which jQuery function is used to prevent code from running, before the document is finished loading?
  • $(document).ready()
  • $(body).onload()
  • $(window).load()
  • $(document).load()
Answer: $(document).ready()

Which method stops an event before the default action is triggered?
  • .preventDefault()
  • medium
  • .end()
  • .stopEvent()
  • .stopDefault()
Answer: .preventDefault()
Which of the following statement best described the following code snippet: $('#myID').animate({width:"90%"}, "fast");
  • Animate the tag with myID from 90% width to 100% width.
  • Animate the tag with myID from 90% width to 0% width.
  • Animate the tag with myID from 90% width to the current width.
  • Animate the tag with myID from the current width to 90% width.
Answer: Animate the tag with myID from the current width to 90% width.