Thursday, October 28, 2010

Concatenation of string using "," and "."

For joining string its always better to use "," since its faster than "." operator.

Single quotes or double quotes on initialization ?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

Thursday, October 21, 2010

include(), require(), include_once() and require_once()

The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.

Cookie and Persistent Cookie PHP

Cookies are created as temporary cookies which stored only in the browser's memory, by default. When the browser is closed, temporary cookies will be erased. A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
  • Temporary cookies can not be used for tracking long-term information.
  • Persistent cookies can be used for tracking long-term information.
  • Temporary cookies are safer because no programs other than the browser can access them.
  • Persistent cookies are less secure because users can open cookie files see the cookie values.

Difference between $a and $$a PHP

Example

$a = "test";
now $$a will be $test.

$$ is actually a reference and $ is a variable.

Difference between 2 dates PHP

Example

$date1 = "2010-12-23";
$date2 = "2010-11-16";
$num_of_days = (strtotime($date1) - strtotime($date2))/(60*60*24);

Friday, October 15, 2010

Test errors on aserting last controller in PHPUnit Testcase

Please add the following to inpect error on running phpunit.

in application.ini

resources.frontController.params.displayExceptions = 1

in testcase

$response = $this->getResponse();
$content = $response->outputBody();
echo $content;

Thursday, October 14, 2010

Setting and checking Cookie in PHPUnit

When using asert functions in PHP test cases using PHPUnit there are some issues in using actons having setcookie option. We cannot set the cookie through testcase so it gives an error on aserting the controller. To modify this we need to add the following code to the action controller.

$request = $this->request();
if($request instanceof Zend_Controller_Request_HttpTestCase)
{
  $request->setCookie(cookie_name, cookie_value);
}
else
{
  setCookie..... // normal set cookie function
}

Friday, October 8, 2010

Difference Between {} and do/end Ruby

Example 1

#!/usr/bin/ruby
my_array = ["alpha", "beta", "gamma"]
puts my_array.collect {
|word|
word.capitalize
}
puts "======================"
puts my_array.collect do
|word|
word.capitalize
end 
 
With braces the code inside is tightly bound and with do end its loosely.
To resolve this just assign the do/end to and array like the example below.

Example 2

#!/usr/bin/ruby
my_array = ["alpha", "beta", "gamma"]
new_array = my_array.collect {
|word|
word.capitalize
puts new_array
}
puts "======================"
puts my_array.collect do
|word|
word.capitalize
end

Thursday, October 7, 2010

Sunday, October 3, 2010

Ajile Web Development

The agile web development model follows planning, requirement analysis, designing, coding, testing, and documentation developing stages parallel. Successful interaction reaches toward to successful completion of application because of customer involvement hence we never met with the condition where we have to change the product due to changes in requirements, correct decision has to be taken by keeping customers confidence and informed choice, minimizing delays of the product. All the tasks are performed at given period, with just enough documentation to be effective.
  • Short timeline
  • Refined Team
  • Clear planning
  • Concise Documentation