PHP Syntax - how would you change it?

While I’m sitting here raging “OH NOES, NOT SHIFT!!!”

Which character would you prefer from (on my keyboard):

[indent]1234567890 `-=[];'#\,./
acbdefghijklmnopqrstuvwxyz
[/indent]

I wish “->” would be replaced with one character, one that doesn’t require the shift key. Dot would be my first choice, but it would completely break backwards compatibility and it would do so in a way that wouldn’t be easy to work around.

You would have to work around string concatenation for starters. Then rework the + and += operators to pickup the workload of string concatenation. I imagine constants would be a monkey wrench in there somewhere too, along with static variables.

Seems like it would just be more trouble than it’s worth.

Inconsistent needle / haystack argument order is probably responsible for a non-trivial portion of php.net bandwidth usage every day.

Again, not easy to change without destroying backwards compatibility.

I would like to be able to do this

abstract class eve_log_base
{
	abstract public function
		character(),
		merge($new_log),
		dps_dealt($zero_fill = false, $round = false);
// ...
}

Instead of this

abstract class eve_log_base
{
	abstract public function character();
	abstract public function merge($new_log);
	abstract public function dps_dealt($zero_fill = false, $round = false);
// ...
}

Works as a module in Apache for faster/better GET/POST handling, much more robust string functions out of box, whitespace preservation inside strings allowing verbose formatting of one’s output with ease, and it integrates to SQL type databases far simpler than most other languages.

I just hate the needlessly cryptic C syntax and the piss poor attempt at implementing objects that goes with it. Objects without pointers is like a automobile without shock absorbers on a dirt road. You might get where you’re going, but you’re not gonna be happy about it. I mean seriously, try to make a self-recursive btree using PHP, you quickly find how PATHETIC it’s object model is.

Or pascal… where a period means property both on Records and Objects. That would conflict with string addition though… I think a lot of this is treading into what Immerse said: “might as well create a new language”… though with things like:

That’s treading into failing to understand under-the-hood decisions that were made as optimizations for speed.

Believe it or not that actually makes the parser run faster, since it can instantly say “variable” instead of having to dig through and figure out if it’s a variable, user function, library function, define, macro, etc, etc. Reduces the number of steps and number of values the bytecoder has to reference against speeding it up a LOT. It’s one of those things common to interpreted languages where filesize is a non-issue but parsing speed is. I suspect this is the same reason that “+” and “.” are two separate typecast additions; it’s faster/clearer when variables are not typecast to typecast the operators instead. Though again, at that point I’d prefer to see strict typecasting with forward declaration… If for no other reason than to prevent typo’s from becoming new variables.

Again, it’s basically an interpreted language not a compiled one, so I imagine decisions like that were made on the basis of “Parse a 5,000+ list of functions, classes and variables, or just check against the variable list at the cost of one byte.”

Hell, moving the $ into javascript would probably speed .js execution as well, since it too is interpreted (and wastes WAY too much headroom on trying to act like something it isn’t)

I dunno, a lot of this ‘shortcut’ stuff just makes me think “Christmas on a cracker, are people really THIS lazy?” Oh noes, you might have to type a meaningful word or two or three extra characters… I mean, does anyone have a LEGITIMATE reason for doing this?

I’m suddenly reminded of this article again:
http://www.ibm.com/developerworks/linux/library/l-clear-code/

For what reason would you require one? The point behind PHP is that it is a system that is easy to use built ontop of a lower-level language. The in-built library is usually written in C so that it can make use of pointers so that the user doesn’t need to use them.

When I drive a car, I put my foot down on the accelerator to accelerate. I don’t need to ask why I can’t move the wheels by hand from inside the car, because I have the tools I need from the driver’s seat.

Off Topic:

I do, I do, I do :weee: Thanks for pointing it out :slight_smile:

Well I personally couldn’t see why you’d WANT begin and end rather than braces, they’re completely ugly things.

Braces seem more… clean-cut to me.

I like JREAM’s suggestions. I think they aren’t needlessly shortened, but make it simpler for the developer. Of course, you could argue that shortening things is unnecessary, but one could also say it’s making things shorter - and shorter code is better for the end-developer. JQuery is a fantastic library, I don’t know what complaints you could have but asking would be off-topic, something frowned upon here.

Bringing pointers into PHP would be like bringing calculus into an abacus. Not only would it make PHP ugly, it is entirely unnecessary. I’d have to ask why, if you hate PHP and C-syntax so much, you even bother with PHP in the first place?

One other thing I’d like is the ability to automatically assign object properties through method declaration.

For example:

class Someclass{
    protected $Database
    public function __Construct(PDO $this->Database){}
}

That’d be better, in my opinion, than:

class Someclass{
    protected $Database;
    public function __Construct(PDO $Database){
        $this->Database = $Database;
    }
}

Of course, you don’t want to always blindly set things like that, but sometimes you do.

I wouldn’t change much, except maybe for:

  • Needle, Haystack argument orders the same everywhere
  • function names to use one standard

Apart from that, I’m pretty happy with PHP. I certainly don’t see any benefit to totally redesigning the language - might as well create a new language in that case.

Use dot notation like in JavaScript. It makes lots of sense because it gives a sense of ownership. It also means you get a better feeling of what a function is being applied to. Example:

newstr = str.replace('_', ' '); //JS
$newstr = str_replace($str, '_', ' '); //PHP

I may have got the order of the arguments for str_replace wrong because it’s inconsistent in PHP, but I’m not going to look it up because I’m sick of doing that. This is the number one annoyance I have with PHP.

I also really dislike the $GLOBALS array and global keyword. Seems hacky. It would be nice to just have a global scope that is accessible from within functions automatically.

Basically, I’d like PHP to be more like JavaScript!

[ot][indent]Quote ScallioXTX:
It should be possible to do something like someFunction()[0], assuming someFunction() returns an array[/indent]

Then you’ll like this recent addition.
[/ot]

I hate the very NOTION of that nonsense, PASSIONATELY. It’s cryptic enough as it is without making it WORSE by taking out legitimate words. That type of bull may have had a place when people were typing or uploading code over 150 baud connections, but today it’s nothing more than a programmer being lazy or not bothering to learn how to type.

I would like to see php be MORE verbose. Replace { and } with Begin and End; for example… give me forward declaration of variables and strict typecasting – that would be nice. POINTERS, oh I’d love to see real POINTERS (which is not the same as references) so you could actually build a binary tree.

But I’m not a fan of C syntax in the first place. It’s needlessly cryptic and as many have said, it seems to exist for the sole purpose of making coding harder for people to do. As the joke goes… http://www.elsop.com/wrc/humor/unixhoax.htm

Though with objects you do kind-of have a point; but it’s not the verbosity that’s the problem, it’s the lack of complex data types like STRUCT or Modula/Pascal’s RECORD, and like most objective C syntax languages it’s a methodology shoe-horned into the language instead of being present by design. No pointers, no complex data types, no strict typecasting… is it any wonder the object implementation is a train wreck?

Of course, it’s an interpreted language, so object use should be kept to those situations where it actually provides a benefit, instead of just slapping it around every blasted bit of functionality to make more overhead and drag performance down to the 9th ring of hell.

Though if I could find a Modula, Pascal or even Smalltalk compiler that allowed for indexed arrays, had as robust a set of string handling, was white-space neutral and preserved white-space inside strings, I’d be writing native apps in the first place instead of even giving PHP the time of day.

Gah, you would actually WANT to do that?!? What on earth are you people smoking (and where can I get some… or is it just you’re too close to Steve-o’s RDF?)… OH NOES, I MIGHT HAVE TO TYPE THREE EXTRA LETTERS PER WORD. (Can you tell I even hate autocomplete?) :smiley:

Whiskey Tango Foxtrot. What, jquery wasn’t bad enough for flushing javascript down the drain, now you want to turn PHP into L33T?

Hmm. think I might have found a new signature.

I’d make it C# like :smiley:

Okay, here goes:

  • :: and -> are annoying to type and I wouldn’t mind if both were replaced with . as in Java, although I do see the merit of different operators for dynamic vs static calls, so maybe replace -> with . and leave :: as is.
  • I don’t really see the need for starting each variable with a $
  • It should be possible to do something like someFunction()[0], assuming someFunction() returns an array
  • A shorthand syntax for array, like $arr = { 0, 1, 2 }. Or create a shorthand function alias for it, instead having to type “array” all the time. What I found really weird is that there exists a function _ which is an alias of gettext. It may be just me, but I don’t use gettext that much that it warrants for such a short hand function, I’d loved it if they’d used that for arrays, i.e., $arr = _(1, 2, 3);

But these have been pet peeves of mine for several years, and I’ve given up hope on some of them. Some things were proposed for PHP6 but didn’t make it (according to the Minutes PHP Developers Meeting).
I guess I’ll just have to live with it :slight_smile:

I like the idea of always having to use the keyword “this” as it clearly lets you know that it’s a method.

I would like to get rid of the dollar sign and add strict typing.

A bummer is we couldn’t really shorthand the public, private, protected with a “p”, haha. But with an automatic application like Notepad++ it suggests the keyword for you so thats useful.

I never use the # sign either,

But outside a static function you still have to specify what class it goes into, so I think it’s probably best to leave it as self::Something(), so that Class::Something() feels consistent with what was written in the class. It would have made more sense if they did this::something() rather than self::, I guess I’m used to it now that I don’t mind.

I actually don’t mind $this-> except when doing things like, I don’t know maybe this:

echo "The Return was: {$this->{$this->NestedObject->Value}}";

Okay below is some shorthand I was just messing around, I think it’s pretty lousy haha.

class X
{
  pro $_Attr;
  priv $_Attr_2;
  pub $Display;

  // m for Method, since it's often called that.
  pub m __construct()
  {
     m:DoSomething();
  }
 
  pub m DoSomething()
  {
     echo 12345;
  } 
}