Sunday, 3 February 2013

annoying computer stuff

This morning I found that networking (internet connection) wasn't working on my Ubuntu VM. Eventually (by the afternoon) I managed to fix it by using Synaptic to uninstall open-vm-tools (and similar packages), then restarting. After I had it working, I installed them again and networking went down again, but then after restarting again, it was okay. Strange.

I'm not sure what they do anyway, as copy / paste still doesn't work between the VM and the host OS.

In the afternoon I did a little work on my pog website. I had an error like:

Warning: require_once(mynamespace/Exception.php): failed to open stream: No such file or directory in /path/to/files in file.php on line XX

I had decided to try using namespacing when rewriting a bit of my site's code into classes. But what I hadn't thought of / realised is that of course when you are in that namespace, any new objects you try to create will be resolved relative to the current namespace, unless you specify an absolute path, e.g.

namespace mynamespace;
class myclass{
 public function wrong(){
  //tries to create a new /mynamespace/Exception object
  throw new Exception();
 public function right(){
  //will create a new global namespace (normal) Exception object
  throw new \Exception();

I did some reading, and it seems that namespaces are only really a good idea for frameworks, classes you might want to use in multiple projects, or large projects. I also didn't realise that all constants and functions will attempt to resolve to the current namespace, and then fall back to the global namespace. So I would guess this should be slower than just working in the global namespace. So I think I'll change my code back to not using a namespace.

No comments: