Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Nov 182010
 

Is PHP pass by reference or pass by value?

Answer:

PHP is pass by value, see the code below:

<?php

class Dog {
	
	public $name;

	public function __construct($name) {
		$this->name = $name;
	}

}

function bar($dog) {
	$dog = new Dog("bar");
	echo $dog->name;
}

$d = new Dog("foo");
echo $d->name;

bar($d);
echo $d->name;

If PHP is pass by reference, the last echo statement will print out "bar" instead of "foo", which is not true.

Nov 172010
 

Change user's timezone setting

Answer:

User can have their own timezone setting.

1. Firstly, you need to find out the timezone string by selecting interactively using the command tzselect command.

2. Append the string to the file ~/.profile

E.g.

# echo " TZ='Asia/Hong_Kong'; export TZ" >> ~/.profile

Nov 152010
 

What is the difference between || and or in Perl?

Answer:

In Perl, sometimes you can use both `||` and `or` to to do the same thing. But the main different is:

  • or has very low precedence, which is useful for flow control

Example:

open FILE,  $file or die("Cannot open $file");   # Work
open FILE,  $file || die("Cannot open $file");   # Does not work , because it it same as the next statement
open FILE, ($file || die("Cannot open $file"));  # Obviously not work