Seva Lapsha at Work

Seva Lapsha working as Java/PHP Developer

Variable declaration in PHP

leave a comment »

Today while playing around PHP and stuff I have been thinking of patterns of handling optionally existing variables.

The 2 most commonly used ones are:


if (isset($var) && $var != null) doSomething($var);
// or
if (isset($var) && $var != 0) doSomething($var);
// or
if (isset($var) && ($var != '') doSomething($var);

if (!isset($var)) $var = something();

However my experience points me that in the majority of the cases it’s enough to check the boolean value of the variable to proceed:


if ($var) doSomething($var);

if (!$var) $var = something();

Which reads very kosher. But then we have a problem of getting notice that the variable is undefined, which is not kosher.

So the way kosherize the snippet is to enforce variable definition before usage. Meaning we would like to either use its value if it’s defined, or to initialize it with null. But of course I don’t like to use isset() for that. So what to do? I found an answer!


$var = &$var;

As you can see in this way you declare further usage of the variable. If the variable exists – it does nothing. If it’s not it is silently initialized with null. No notices are yielded. Also it’s better than if(isset()) combination because of readability – the only alphanumeric tokens on the line are variable names.

Isn’t it nice?

Written by Seva

2009-09-28 (September 28) at 02:21:10

Posted in development, php, thought

Tagged with

SyntaxHighlighter

leave a comment »

Shame on me! I’ve discovered that wordpress.com provides syntaxHighlighter functionality just today. So I hurry to report that the only 2 posts in this blog, which contain code snippets have been immediately converted:

<a href="http://sevalapsha.wordpress.com/2008/06/26/copy-nodes-xml-documents-java-dom/">
    Copying nodes between XML documents with Java DOM
</a>
&amp;
<a href="http://sevalapsha.wordpress.com/2008/08/11/prototype-google-analytics-javascript/">
    Prototype styled Google Analytics javascript snippet
</a>

BTW, isn’t it weird I don’t have one snipped in PHP yet?

Written by Seva

2009-09-16 (September 16) at 09:14:52

Posted in html, java, javascript, php, software, web, xml

Tagged with

Moving on

leave a comment »

Today was the 1st day of me working in the new company (yes, my dear friend, I bid farewell to Nielsen Online) – EasyToBook GmbH – as Software Architect. Unfortunately I’ve got no chance to either design any architecture or to develop any software yet, but succeeded to meet nice and talented people and spent some sweet time reading the documentation.

Written by Seva

2009-08-26 (August 26) at 10:21:12

Posted in development, future, php, software, web

Tagged with

Eclipse Committer Emeritus

leave a comment »

Time passes and doesn’t wait, and some of the plans don’t be realized, you know. So due to last year inactivity my PDT committer rights were expired and I was appointed with the Eclipse Committer Emeritus status. How sad.

I will still try to not loose connections and relations with my good old friends and will do my best for the project’s success (even if it will be just mental support).

Written by Seva

2009-08-12 (August 12) at 12:24:55

Posted in development, eclipse, past, pdt

Tagged with

Iterators in PHP

leave a comment »

Recently, while playing with Scala/Python/PHP comparative implementation of lazy algorithms (I will hopefully describe them some days later) with colleague and friend of mine Michael Fuks, I sorrowfully discovered that, despite there are several SPL units, which define basic Iterator interfaces and functionality, most of the functionality available for arrays is missing for Iterators.

So I decided to fill the gap and started to reimplement for Iterators the applicable non-trivial array functions and also started trying to simulate iterator comprehension (generator routines) in PHP which is missing there too. For this reason I opened a GoogleCode project of php-iterator-utils – please observe my first experiments here.

In addition I need to notice that latest NetBeans build (6.8) branch has great PHP 5.3 support and feels more stable, fast and functional than Eclipse PDT :(

Written by Seva

2009-08-03 (August 3) at 03:46:35

Programming in Scala

leave a comment »

Got the Programming in Scala eBook. I hope to get time and build an experimental Eclipse Plugin with it.

Written by Seva

2009-07-05 (July 5) at 11:41:19

The Java Explorer

leave a comment »

I’m happy to announce that Eyal Schneider, the collegue of mine, has been finally convinced to open a blog to share his knowledge and experience.

Written by Seva

2009-05-24 (May 24) at 11:59:41

Posted in development, java

Eclipse Galileo RC1 Update Manager RT Equinox P2 is still not good enough for me yet

with one comment

I’ve just failed to install JDT over clean Eclipse Platform RC1 (and this time a bug has been opened):

An error occurred while installing the items
session context was:(profile=PlatformProfile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, operand=null –> [R]org.eclipse.ant.ui 3.4.0.v20090504, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction).
Error while loading manipulator.
Error while loading manipulator.

Retrying causes the message immediately. Reverting to the previous installation stage does not help. Restarting does not help either.

It’s very sad that what they call Release Candidate is still rare. Waiting for the release…

Written by Seva

2009-05-21 (May 21) at 01:19:32

Posted in eclipse, integration, java

PHP Frameworks popularity estimation

with 2 comments

About 2.5 years passed since I posted the development activity comparison of major PHP frameworks. Since then I’ve got about 4.5k hits from search engines, which IMHO is not such a bad sample to summarize people’s interest in each of them.

Again, no conclusions – just pure numbers :)

http://tr.im/lnXq:

Query Hits Zend CakePHP Symfony CodeIgniter Prado Seagull eZ
zend framework vs cakephp 573 573 573 0 0 0 0 0
zend vs cakephp 319 319 319 0 0 0 0 0
cakephp symfony 258 0 258 258 0 0 0 0
zend vs symfony 254 254 0 254 0 0 0 0
cakephp vs zend framework 217 217 217 0 0 0 0 0
symfony vs zend 210 210 0 210 0 0 0 0
zend framework vs symfony 187 187 0 187 0 0 0 0
symfony vs cakephp 185 0 185 185 0 0 0 0
zend framework vs 176 176 0 0 0 0 0 0
codeigniter vs zend framework 143 143 0 0 143 0 0 0
prado framework 139 0 0 0 0 139 0 0
cakephp vs zend 139 139 139 0 0 0 0 0
symfony vs zend framework 138 138 0 138 0 0 0 0
zend framework cakephp 131 131 131 0 0 0 0 0
prado vs zend 103 103 0 0 0 103 0 0
zend framework vs codeigniter 84 84 0 0 84 0 0 0
cakephp vs symfony 82 0 82 82 0 0 0 0
prado vs cakephp 81 0 81 0 0 81 0 0
prado vs symfony 80 0 0 80 0 80 0 0
zend vs codeigniter 76 76 0 0 76 0 0 0
zend or cakephp 69 69 69 0 0 0 0 0
codeigniter vs cakephp 68 0 68 0 68 0 0 0
codeigniter vs zend 62 62 0 0 62 0 0 0
zend vs code igniter 60 60 0 0 60 0 0 0
cakephp zend framework 59 59 59 0 0 0 0 0
codeigniter vs symfony 55 0 0 55 55 0 0 0
cakephp symfony zend 52 52 52 52 0 0 0 0
cakephp vs prado 50 0 50 0 0 50 0 0
symfony zend framework 48 48 0 48 0 0 0 0
cakephp vs codeigniter 48 0 48 0 48 0 0 0
zend framework vs code igniter 46 46 0 0 46 0 0 0
zend framework vs. cakephp 46 46 46 0 0 0 0 0
symfony vs codeigniter 45 0 0 45 45 0 0 0
symfony vs prado 39 0 0 39 0 39 0 0
zend vs prado 37 37 0 0 0 37 0 0
zend cakephp 37 37 37 0 0 0 0 0
zend framework symfony 36 36 0 36 0 0 0 0
zend framework or cakephp 35 35 35 0 0 0 0 0
prado symfony 35 0 0 35 0 35 0 0
seagull vs cakephp 34 0 34 0 0 0 34 0
zend framework versus cakephp 32 32 32 0 0 0 0 0
Total 4568 3369 2515 1704 687 564 34 0
Interest Ratio
73.75% 55.06% 37.30% 15.04% 12.35% 0.74% 0.00%

Written by Seva

2009-05-15 (May 15) at 01:33:24

Windows XP x64, Cisco VPN Client, VirtualBox and Windows 7

leave a comment »

As you can easily guess from the subject, I had compatibility issue with installing Cisco VPN Client over my Windows XP x64 installation – the bastards refuse to release 64-bit version drivers. That was not a big deal for me, since I used to connect to the office from my ThinkPad T42 anyway.

But just these days Windows 7 has been pre-released, so to play with it a bit I installed the x86 version of it over VirtualBox.

Hence, in this very moment I’m tunneled through 6 network interfaces:

  1. Some neighbor’s wireless router
  2. Wireless adapter
  3. VirtualBox’s adapter
  4. Cisco’s virtual adapter
  5. Cisco’s VPN server
  6. Office workstation’s adapter

Written by Seva

2009-05-07 (May 7) at 01:23:37

Posted in leisure, software

Tagged with