Learning PHP – Step 3 Basics

Following previous posts, lets start with the basics.


– Always start with $ and can have the following chars _ [a-z] [A-Z] and [0-9]. the first symbol must be an _ ou a letter.

$count = 0;
$name = “José Cruz”


What about types? If you know python, ruby or the “var x = 0;” construction from C# you know how PHP works. It converts the variable for the type defined by the value initialized. For instance: $count = 0; will be an “integer”.

Lets use some variables in our script:

        Learning PHP – Step 2
                $name = "José Cruz";
         echo $name . " is starting to understand PHP!";

If you run the script above it will display “José Cruz is starting to understand PHP!”

PS: The dot between $name and “ is starting… ” is the concatenation in strings. This is new. Other languages usually use the plus sign or some function to do it.

The operators are the same as C or mainstream languages:

Arithmetic: +, ++, –, –, *, /, %

Assignment: =, +=, –=, *=, /=, %=, .=

Comparasion: ==, <=, <, >= >, <>, !=

Logic: &&, ||, !

PS: You can use “(“ and “)”

Some examples:


$a = 5 + 2 * (7 + 5);
$b = $a –4;
$c = $a / $b;
$even = 10 % 2;
$a+=7; // same as $a = $a + 7;
$even = 10;
$even %= 2;
$verytrue = 2 < 7;
$veryfalse = 6 >= 3;
if( $a > 3 ) …. // future post we talk about if and other statements.
if( $a > 3 && $b < 10 || $even == 0 ) …


As with other languages:

– Unary operators precede all other ones ( “!” )

– then: *, / and  &&

– Last: +, –, ||


Lets try this in our php website:

        Learning PHP – Step 2
                 $name = "José Cruz";
         $even = 10 % 2;
         $odd = 10 % 3;
         $someValue = $even * 4;
         echo $name . " is starting to understand PHP with some operators" . "
         echo "even values: ". $even . "
         echo "odd values: ". $odd . "
         echo "some value = " + $someValue . "


Run it!

Next post: statements.

Technorati Tags: ,,,,
WordPress Tags: language,programming,Variables,Basics,PHP

Learning PHP – Step 2

Following my previous post I’m now preparing an environment to develop in PHP.

1) Install XAMPP – There are other alternatives, but this one, after some research was my choice. Why? Because in the future I’m thinking developing some skills in Perl and with XAMPP it’s a 2 in 1! (Besides mysql included!)

2) IDE – I’m trying Netbeans 7.1. There are a lot others IDEs out there like: komodo, phpstorm, phpide, aptana, eclipse, phpdesigner. My choice probably it’s not the best one, but I develop in Visual Studio and Eclipse and as a Oracle trainer, sometimes I have to use Netbeans. I will try it, if the experience gets troubled I will change to another and keep this learning. I think, anyway, the experience will be always positive.

I’m now following the steps to create a project in Netbeans…

  • New Project PHP
  • Advantage – Netbeans detected my xampp instalation and discovered where to put the php files.
  • Project name: LearningPHP (in my drive sits at: D:\xampp\htdocs\LearningPHP)
  • Local Web Site
  • Project URL: http://localhost:8001/LearningPHP/
  • I will not use any PHP framework… maybe in a future post I’ll try one besides WordPress.

After the wizard I have the file below already created:

index.php (the first file in any web tech is always index.

                // put your code here


Now I will change the Title and put some basic code inside the

        Learning PHP – Step 2
                 echo "My second step to learn php!";


Let’s run it (In Netbeans just hit the “play”!

PS: Make sure xampp is running and the port it’s the correct one. In my example the url is: http://localhost:8001/LearningPHP/index.php


and the result, as expected, it’s the browser output:

My second step to learn php!


Now, I have an environment to run php and a first “hello word” example.

Next post: The usual language basics of php!

Learning PHP – Step 1


I develop in several programming languages like C#, VB.NET, VB, Java, JavaScript, Python, Groovy, Powershell, PL-SQL, T-SQL, a little of Ruby, C, C++, Assembly (in the last years not so often), Prolog, List/Scheme, F#, Perl and and few others less used. I’ve read and I can understand PHP, from the knowledge I have from “C” Languages, but I never developed a complete project in PHP, and I don’t know if in the future I will need to do it, but from what I’ve been reading PHP is used in the TOP CMS Frameworks/Applications as WordPress, Drupal, Joomla, etc.

I’m thinking to create a synergy here, I will deep my understanding and knowledge about PHP and WordPress, tweaking my blog, this blog! Which I think will enrich my CV and, in the future, my career, making me a better team leader and software architect.

Starting PHP.

1) It’s a language to use in web sites.

2) You mix HTML with PHP, which is different from ASP.NET and JSP for instance. To differentiate the HTML from PHP you use in the middle of the HTML. The server will know how to process the PHP and merge it with HTML.

My first example in PHP


This code will output “My first PHP!” in the browser.

Great! It’s the first step!

Next Post let’s install the software we need to run this example. Then, the sky it’s the limit!

The twin paradox

One of the most fascinating things to me are the paradoxes. Its something that’s true but its false, its something that’s right but it’s wrong, it’s something that it is not!

There are a lot all around us, and I will try to show some of them in future posts.

Lets see one very simple:

How many of you have already seen a page in a book with the sentence:

“This page was intentionally left blank”

This is a paradox! If the page was really blank there were no words in it. But the words are in it to say it, but they say the opposite. We understand it, but the meaning it is true and it is at the same time false.

The video below show the twin paradox. See if you understand it. (Clue: They are twins but…)

Physics in a Minute: The twin paradox


This video was taken from New Scientist

Manage the system, not the people

When you are working with people, one thing you must expect and be sure about: “You are working in a complex system, not in a complicated one” (See a previous post to know the difference).

When you work in a complex system, there are some unpredicted behaviors, as everybody who works with people already know. So, you can’t control the people, you can try a lot of strategies to do it, like: persuasion, influence, fear, bonus, promotions, etc. Some of these strategies are good ones, but others are malicious and just show how bad a manager is as a manager and as a person.

But whatever your strategy is (hope you choose the good ones for everybody), more or later you will have “surprises” because you thought you could control a complex system.

So, how can I manage a team if it’s not manageable by nature and have some unpredicted behavior?

You can minimize the unpredictability managing the system, creating the rules, not rules for the people but for the system. If you are a project manager, or a team leader, you must give freedom to the team members, but show them the constraints that you think will influence the behavior of the system, or in this case, the team performance, motivation, etc. The team, as a complex system with people, will experience a wonderful thing, a complex system growing and self-organizing with itself. I have already experienced this in some projects where the project manager was out or gave this managing opportunity.

This seems to be a simplistic view of software teams’ management, but if you stop and think for a while I am sure you reach this conclusion, or similar, because when you are managing people you are managing the unpredictability which seems to me a paradox, and it is! So, this is why you must let the system go, inside your parameters.

Want an example of this? Traffic.

No one is controlling the people inside the car, and sometimes they really have an unpredictable behavior, but, for the good of everybody in this system (with some flaws but fortunately just a few), the system self organizes. There are anyone controlling the drivers? No! There are unpredictable behaviors? Yes, they are people! The system works? Yes, I use it all the time! This works for software developing teams to, really! Do you have the courage to try it out?

It’s a bug! it’s a feature! Its just code! Its…super-whatever!


One of these days someone from my team told me about a story where someone closed a bug with the comment: “Works as coded!”. Well, its true, indeed, and its very difficult to discuss this argument. Probably his project manager will not disagree (I hope) with the comment but certainly will disagree by closing the “bug” with such argument!


Once in a while, I do training, I’m a Microsoft Certified Trainer and a Portuguese Certified to do training in any subject. (This doesn’t mean I can really do training to anyone in anything, its just means Portugal accept me to do training).


In one of these trainings I was teaching my students about software development cycle, and between roles, risk management, project management, etc.… one of the lessons was about bugs. What is a bug?


“A bug its nothing more than a problem in the development that its visible in the final product to the customer. “


You can disagree with this sentence, but think in it for while?

– Do you really could design all the possible tests (unit, functional, etc) in a way that you can guarantee that’s impossible your application/system has no bugs?


Lets dream (for a big application) you can! And you conclude that you need to  develop about 2000 tests with 10000000 input states for these tests, and expect 190000 different outputs from these inputs. (for clarification, you must test success and probable/expected failures)

If you are developing, for instance a web site, and you know that from all these bugs, only 1/100 could be visible or could bring trouble (semantic and/or behavior) to your application, it means you will not have to correct all the other 9/100 bugs discovered. To your customer, its important to pay more development weeks to the team to correct these 9/100 bugs? And if the customer its your company, I will bet with you that the project manager doesn’t want these 9/100 bugs corrected! It will not increase any value to the final product, it will not have any visible impact to the final customer, the only think that will increase it’s the project expenses.


As a developer, as a team leader, and as a project manager, something that I learned it’s: Any technical think in a project must have a business impact, and the goal of a member of team, such as leader, developer or project manager its to minimize the expense and increase quality of the product. This quality is observable by the final customer and not from the developer team. I think, this is applied to any subject, not only software development.


In a future post, I will merge this bug concept with the complexity/complicated subject post I have wrote before, and we can really have some fun discuss this intersection subjects, since that, most of times, a really software bug its something about application behavior, and behavior its related with predictability,  not related with understanding (at least in complex systems). Read my old post ”Complex or Complicated” and I think you will know what to expect from my future post.


In the future, be more nice with the bugs!

Complex or Complicated


Usually these are words used as synonymous, when in fact they are orthogonal between them.


When we are talking about “complicated”, we are explaining something about linearity. Something is “simple” or “complicated”. What does this mean? Let’s see an example:


Something “simple”: understanding how a bicycle works. I think we don’t need to a genius for this, you analyze the “simple” engine and after some minutes (hopefully seconds) you’ve figured it out!


Something “complicated”: How a clockwork works. If you try to analyze it, you will have to think and analyze the mechanics for a long time, write a lot, until you figure out how the watch works, and how all those components fit together to give you an “accurate” time. It’s a task that’s its possible, takes some time, but you can analyze it linearly until you find the solution that explains it 100%.


Click image below to follow to a site explaining how this works!


Terminology of the geartrain


The image should be perceived has trying to show a complex system, but its not, it’s just very complicated, but with a 100% detailed explanation how the engine works!



So, we have Simple and Complicate, as 2 grades of linearity.


How about “Complex”?

When we say “Complex”, we are talking about behavior, not linearity. We can take several degrees of behavior but let’s analyze 3 very understandable:


“Predictable”: Something that we can predict, we could not understand it totally, but we know how it responds: For Instance: I jump, and gravity pushes me down again. Do I understand gravity? Something in school…. but…. its invisible and pushes me down! 😉


Complex: Something that we can somehow predict but sometimes arises some unexpected behavior.  For instance: Social interactions in a small company, home, software projects with several components in different tiers. Or Poker, a game with rules, but not predictable.


Chaotic: Like complex systems, but with plenty unexpected behavior factors. For instance: Events in  a big city. weather sometimes is complex and sometimes chaotic.





So, I hope in the future when someone use the word  complex knows that’s its different from complicated. Saying complicated means I just need tools and time to figure it out, and complex I could have tools and time and take my whole life and not discover or even completely predict the system.





Hopefully in future posts dive deeper on this subject. It’s a very popular one in software team leading.

Silverlight 4–Out of Browser Authentication

One of the things that was very difficult to find, even in silverlight forums, was a way to know, in a simple way, what user is authenticated when a Silverlight 4 application is running Out-Of-Browser. I’ve found many information about using WCF, RIA, etc, buts it was not what I wanted. So, I investigated a little more about trying to find out how isolated was Silverlight from windows.


At first sight, Silverlight should act as flash, isolated  as possible from the OS, but when running in Windows (as out-of-browser, thank you Microsoft for this “Air” copy”), I should access windows stuff, since I’m exclusively running in Windows, so the isolated thing doesn’t matter anymore! Wrong! I can access only some windows stuff! The .NET framework for Silverlight it’s a little bit “small” in features!


My first try, was to connect to SharePoint using ClientContext from Sharepoint Client API for Silverlight (My application needs some SharePoint list items). When inside SharePoint I just ask about “who am I”, and SharePoint , running in a windows domain, should respond to me with the authenticated user! Was successful! But with some hick ups every time someone from systems staff changed IIS Windows Authentication configuration or some SharePoint tweaks. The problem: I want to run an application and I need to use a SharePoint just to ask about “Who I am”? Yes, you are right! As we say in Portugal, “A cannon to kill a fly”.


Since my Silverlight app its running out of browser I needed to find a way to use directly windows. I thinks it’s a logic thinking!

When a Silverlight App its running outside browser with Elevated Privileges it can access COM stuff! Well, with this “opening”, the sky it’s the limit!


Thanks to “dynamic” word from C# we can do this:



As you may see, I use a COM Object that returns Active Directory information, including the User logged in.  (OK, the format it’s the AD CN=xxx,CN=xxx, but I now we have a door to the windows, very useful!

ORA-00984: column not allowed here

If you try to find information about this error probably you will reach the page: http://ora-00984.ora-code.com/, but read information that will not help you.

In one of my PL-SQL Scripts I was getting this ORA_00984, I’ve followed the advice from the above URL without success, I was just using a Stored Procedure parameter, not an expression or the name of another column.

The solution I’ve found:

– See if the next column (above “col3_column_with_error”) in the “values” statement is correct. In my case, the next column was with a wrong name, but the error was reported on the previous column (col2_reported_as_error).

Something like:

INSERT INTO MYTABLE (col1, col2, col3) values (col1, col2_reported_as_error, col3_column_with_error)

Hope it can help you!

Great video about education!

Education, Inovation, creativity

Bad Behavior has blocked 128 access attempts in the last 7 days.

Hyper Smash