News for hackers. Stuff that matters.
Re:A Built-in Web Server For PHP by acabal on Wednesday March 02, 2011 @06:15PM (#2281874)
Oh god... as if configuring Apache for a non-trivial site wasn't complicated enough, now we'll have the full genius of those responsible for PHP's function naming conventions writing their own web server? Is this really necessary? Why not spend the time making PHP's namespace support not suck, or working on the SPL?
Re:A Built-in Web Server For PHP by ary on Wednesday March 02, 2011 @06:31PM (#2281925)
Curious as to why you think PHP's namespace feature (I'll assume you mean the real one introduced in 5.3) sucks.

It seems like you didn't read the whole RFC. The configuration is actually very simple (just the command line options), and not meant to be a front-facing HTTP server.

Re:A Built-in Web Server For PHP by acabal on Wednesday March 02, 2011 @07:06PM (#2282061)
Off the top of my head, because when I want to reference My.Namespace.MyClass.Foo(), I have to do something like:

  use \My\Namespace;
  $var = new Namespace\MyClass();
  $var->Foo();
I have to remember and type the parent namespace for every imported class I want to use. In a big project this gets to be too much typing and too much for my brain to remember. Contrast with say, C#:

  using My.Namespace;
  MyClass var = new MyClass();
  var.Foo();
You import a namespace, and the compiler figures out what goes where without you having to remember anything.

Plus the weird exceptions required for backwards compatibility, and the global namespace: I often forget where a root \ is required and where it isn't (not when declaring a namespace, but often--not always!--when referencing one). And of course there's the monstrous choice of namespace separator.

End of the world? Not really. Sucks? Yeah. And possibly a dealbreaker for me for larger projects with complicated namespaces and lots of classes.

I'd love for this to be just a misunderstanding on my part, because it would make my life a lot easier if PHP namespaces where more like C# ones!

Re:A Built-in Web Server For PHP by ary on Wednesday March 02, 2011 @08:16PM (#2282259)
Your PHP example is possible to write in a way that is nearly identical to the C# you provided. Why are you prefixing Namespace\MyClass(); when you declared your namespace scope in 'use \My\Namespace'? Your assignment can just be:

  $var = new MyClass();
This brings it pretty much in line with your C# example. Have you read the PHP docs on namespaces?

http://www.php.net/manual/en/language.namespaces.basics.php

Re:A Built-in Web Server For PHP by acabal on Wednesday March 02, 2011 @08:38PM (#2282306)
That's the point; the PHP doesn't compile without the namespace prefix. In fact I just tried it to make sure I'm remembering right.
Re:A Built-in Web Server For PHP by ary on Wednesday March 02, 2011 @09:47PM (#2282514)
I was taken aback when I tested this for myself as my initial reading of the PHP docs lead me to a very different conclusion. You are indeed correct, and in my opinion that is very broken. Touché.
Re:A Built-in Web Server For PHP by soulclap on Wednesday March 02, 2011 @07:25PM (#2282111)
Haven't worked with the PHP namespaces a lot myself yet but there seem to be more convenient ways: http://www.rooftopsolutions.nl/blog/taking-advantage-of-php-...

And a good read on PHP namespaces in general: http://weierophinney.net/matthew/archives/254-Why-PHP-Namesp...

Re:A Built-in Web Server For PHP by roel_v on Thursday March 03, 2011 @07:28AM (#2283725)
You can't import everything from a whole namespace, but you can do it on a per-class basis. The following works as expected:

    namespace My {
        class MyClass { public function Foo() { echo 'Foo'; } }
    }

    namespace {
        use My\MyClass;
        $var = new MyClass();
        $var->Foo();
    }
Re:A Built-in Web Server For PHP by orthecreedence on Wednesday March 02, 2011 @06:17PM (#2281882)
At least the web server isn't written in php...
Re:A Built-in Web Server For PHP by kingkilr on Wednesday March 02, 2011 @06:37PM (#2281952)
Actually it's kind of sad that it needs to be in C, most sane language would implement their server in themselves.
Re:A Built-in Web Server For PHP by ErrantX on Wednesday March 02, 2011 @06:41PM (#2281969)
Why? Web Applications and Web Servers are two very different things with different language requirements. Seems sensible to pick the strongest languages with which to build the whole package.
Re:A Built-in Web Server For PHP by mahmud on Wednesday March 02, 2011 @07:10PM (#2282072)
I guess you don't push web servers. They're "apps", not system software. Anybody who deploys non-trivial web-apps knows this. Per-app web servers, standing behind a proxy, with a shared session-db is the most ideal way to get things done.

At this point in the game, Apache-class servers are glorified proxies, and occasionally dole out static data when you're not using a CDN.

I have customized my web server so much, I would've had to wait for years to see the changes in Apache, nginx or lighty, if ever.

Re:A Built-in Web Server For PHP by kingkilr on Wednesday March 02, 2011 @08:02PM (#2282226)
Because most sane languages aren't just for writing web apps, they're for writing programs.