April 4th, 2009
We can ask a function return by reference by adding a & before function declare. See example:
function & pass(& $a) {
return $a;
}
function duplicate(& $a) {
return $a;
}
$a = array('a'=>'a');
$b = duplicate($a);
$c = & pass($a);
$b['a'] = 'b';
echo $a['a'], "\n";
$c['a'] = 'c';
echo $a['a'], "\n";
output is:
a
c
You will see, the trick here is: don’t forget to put an ‘&’ before the function of assign operation. Otherwise, the assign operation will make a copy of the returned reference.
Posted in Lang Code | 3 Comments »
April 4th, 2009
See codes below:
$a = array('a'=>'a');
$b = $a; // $b is a copy of $a
$c = & $a; // $c is a reference of $a
$b['a'] = 'b'; // $a not changed
echo $a['a'], "\n";
$c['a'] = 'c'; // $a changed
echo $a['a'], "\n";
The output is:
a
c
Also, we know that when we use [] to get a data from an array, this return the reference to the internal data. So it we pass in a reference of data to array, and then we get the data from the array. This operation will change the original data.
See below:
$a = array('a'=>'a');
$b = array();
$b[] = $a;
$b[] = & $a;
$b[0]['a'] = 'b';
echo $a['a'],"\n";
$b[1]['a'] = 'c';
echo $a['a'], "\n";
output is:
a
c
Posted in PHP | 1 Comment »
April 2nd, 2009
Finally, I am trying the twitter.
Posted in Windows | No Comments »
December 3rd, 2008
Due to the problem of Fedora 10 ‘s new rpm 4.6, the snmpd can not start with a segment fault error.You can temperary work around this by adding a line to /etc/sysconfig/snmpd
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -I -hr_swinst"
Posted in Lang Code | No Comments »
June 14th, 2008
Under fedora 7, you might find an incorrect time problem for java log4j output. The reason should be F7 using America/New York as the timezone name for New York, which is invalid for Java (should be America/New_York, with the underline instead of space). A solution is using system-config-date tool change it to America/Toronto.
Posted in Linux | No Comments »
May 17th, 2008
disable “Network Manager” service, enable: “network” service. Then you can set the static ip by editing /etc/sysconfig/network-scripts/…
Posted in Lang Code | 1 Comment »
May 4th, 2008
Sometimes, you project will have dependency on a jar which is not in official maven repository, and maybe it is propriety jar file which will never be part of maven repository. In this case, you have to put it to your local repository your self to solve the dependency.
There is a install plug in to do this job, which is something like:
mvn install:install-file -DgroupId=<your_group_name> \
-DartifactId=<your_artifact_name> \
-Dversion=<snapshot> \
-Dfile=<path_to_your_jar_file> \
-Dpackaging=jar \
-DgeneratePom=true
For example, you want to install the danga’s memcached client plugin, you can do:
mvn install:install-file -DgroupId=com.danga \
-DartifactId=memcached \
-Dversion=2.0.1 \
-Dfile=java_memcached-release_2.0.1.jar \
-Dpackaging=jar \
-DgeneratePom=true
This will add the memcache jar into your local Maven2 repository under groupId com.danga and artifactId memcached, you can then edit your pom.xml adding this dependency.
However, the maven eclipse can not recognize it since it always search from public repository.
Posted in Lang Code | 8 Comments »
May 3rd, 2008
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project’s license
README.txt Project’s readme
Posted in Lang Code | No Comments »
May 3rd, 2008
You can use maven release plugin to make your release job much easier. it will automatically test build the project and run all unit test. After that, it will create a tag for you, and then update the current snapshot version to a newer one.
For using the release plugin, you will need to set up the scm info first:
<project>
...
<scm>
<connection>...</connection>
<developerConnection>...</developerConnection>
<url>...</url>
</scm>
The ‘connection’ tag is for read only checkout, and ‘developerConnection’ is with commit permission.
The value of them will look like: ‘scm:svn:http://….’, given you are using SVN/Webdav as your SCM system.
After that, you can use: ‘mvn release:prepare’ for preparing your release. And you can use ‘mvn release:perform’ for doing the release.
Please note that if you don’t have a repository set up, the release:perform will fail. That’s okay is you don’t really need to release it by repository. You can just delete those 2 generated release property file.
Posted in Linux | No Comments »
May 3rd, 2008
By default, the maven will use the compiler source check level to 1.3 and target version to 1.1 for maximum artifact compatibility. However, in most of your project, you don’t need such compatibility. In contrast, you will want to use more recently language features: like assertion, generic type of container, and so on. You can do that be indicate the compiler source and target requirement.
First, from Eclipse IDE, select “maven – add plugin”, add the maven-compiler-plugin, the lastest version should be 2.02. This will add some elements to you pom.xml like:
...
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
</plugins>
</build>
...
you can add attibutes after version, like:
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
This will set the source check and target check version to jre 6.0. You will notice that although sun has change this naming scheme from 1.x to x.0 from jre 5.0 on, but maven still using 1.x scheme.
Posted in Lang Code | 1 Comment »