26 May 2009

PHP Theory

  • # For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:



and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.


  • # chunk_split
echo chunk_split("My name is Jankit P Shah", 2, "
");
It will give output like:
My
n
am
e
is
J
an
ki
t
P
Sh
ah


  • # What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

  • Difference between for and foreach?
    'For' is used to execute a loop of any n number of time
    'Foreach' is used to execute a loop of each and every element of an array

  • How can I execute a php script using command line?

    Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.
    Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

  • What is the difference between var_dump and print_r?
    var_dump will give output of each element of an array with its size and type.
    print_r is used only to print the element of an array

  • Name of PHP function which can create runtime variables for the index of each array.

    $size = "large";
    $var_array = array("color" => "blue",
    "size" => "medium",
    "shape" => "sphere");
    extract($var_array, EXTR_PREFIX_SAME, "wddx");//here prefix "wddx" will be added if any same name of variable is already set

  • What are the different types of errors in php?

    Three are three types of errors:
    1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.
    2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
    3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.

  • Joomla- what are the difference of module, extension and plugin?

    Components

    A component is in fact a seperate application. You can think of a component as something that has it's own functionality, it's own database and it's own presentation. So if you install a component, you add an application to your website. Examples of components are a forum, a newsletter, a community system, a photo gallery, etc. You could think of all of these as being a seperate application. Everyone of these would make perfectly sence as a stand-alone system. A component will be shown in the main part of your website and only one component will be shown. A menu is then in fact nothing more then a switch between different components. You can compare it a bit with your windows taskbar, where you see a tab for each open application.

    Modules

    Modules are extensions which present certain pieces of information on your site. It's a way of presenting information that is already present. This can add a new function to an application which was already part of your website. Think about latest article modules, login module, a menu, ... . Typically you'll have a number of modules on each web page. The difference between a component and a module is not always very clear for everybody. But if you think about it, it's really not that difficult. A module doesn't make sense as a standalone application, it will just present information or add a function to an existing application. Take a newsletter for instance. A newsletter is a component. You can have a website which is used as a newsletter only. That makes perfectly sense. Although a newsletter component probably will have a subscription page integrated, you might want to add a subscription module on a sidebar on every page of your website. You can put this subscribe module anywhere on your site. You'll probably agree with me that a site with just a subscription module and no actual newsletter component would be rather ridiculous.

    Plugins

    They used to be called mambots in Joomla 1.0.x, but since Joomla 1.5.x they're called plugins. A plugin is a function which is performed on a part of Joomla before this part is shown. This part can be on content, on the editor, on the complete system, etc. This might seem a bit abstract, but you'll understand it with an example. Let's take one of the plugins of Ulti Joomla as an example. This is a plugin which can make a reflection of the images you use in your content articles.


No comments: