I was trying to make CakePHP dynamically add javascript and css files, but I kept getting the error Undefined variable: javascript. I was sure that I had added the Javascript helper in the app_controller. After some results on google I found out that if you misspell a helper name then CakePHP will throw this error. It has nothing to do with the object $javascript not being defined.
So I changed:
var $helpers = array('Form', 'Html', 'Javascript', 'Time','Sessions');
to
var $helpers = array('Form', 'Html', 'Javascript', 'Time','Session');
Session is not in plural…
We found a small bug in our codebase the other days, which led to a funny discussion about how PHP acts in different situations.
Try look at the following example. What will $i be?
$i = 10;
$i = $i + 2 + $i = $i + 5;
echo $i;
Give an answer before you plot it in the console
Ruby will give the same answer:
i = 10
i = i + 2 + i = i + 5
puts i
Here is another one:
$d = 0;
$d = 2 + $d == $d = $d + 2;
echo $d;
When doing OOP in PHP it can be a pain to include all the different class files. The code becomes really ugly with lots of require_once() function calls and you risk to include classes that are never used.
This is were object autoloading comes in handy. In PHP 5 it is now possible to define a functions called __autoload() which takes the name of the class as parameter. The function will be called when trying to use a class or an interface that has not been defined yet. The function could look like this
function __autoload($class_name){
require_once('/classes/'.$class_name.'.php');
}
$obj = new MyClass(); //will load MyClass from /classes/myclass.php
MyClass::getSomething() //will load MyClass from /classes/myclass.php
After having spent a few hours trying to get an image uploading script to work in php on my mac, I found out that the GD Library is not pre-installed with PHP. Why is that? I thought that the GD lib was a standard module and I know it is installed in the XAMPP package for windows. I have not installed the lib yet, but I found this page which explains a how-to, but by looking at the comments it seems that it is not as simple as it should be. People are really having dififculties getting it to work. I will try to install it when I have some more time and post my result here.