SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 76
  1. #1
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    PHP Syntax - how would you change it?

    The poll on the main sitepoint page at current asks the user what they would like to do to rename the JavaScript 'function' keyword.

    So, that make me think - what would you do to change PHP's syntax?

    Of course the characters must be available on the typical keyboard, so signs like the british pound £ and the euro aren't viable.


    I'd get rid of '$this->' and 'self::' in object-oriented programming. I cannot stand it. I think methods and properties should be accessed like #method() and #property rather than $this->method() and $this->property (# is a comment operator, but it is rarely used compared to double-slashes //). I also think static functions and variables should be accessed with a double-colon alone, e.g. ::function() and :: property. (without the space; :: + p = : in vbulletin )

    This would also apply in the declarations. I think the function keyword is unnecessary because the parser could tell whether it was a property or method.

    I'd also allow multiple function declarations under the same function name but using different parameters. That would save quite a lot of framework-development pain!

    I'd also allow arrays with the square braces, rather than the array function.

    So ideally:
    Code:
    class Someclass{
        #variable = 'hello';
        #func(array $var){
            printf($var);
        }
        #func($var1, $var2){
            #func(['one' => $var1, 'two' => $var2]);
        }
        #__Construct(){
            #func(#variable, 'world');
        }
    }
    It looks a little confusing and the forum PHP highlighting certainly won't help so I left it as plain code.

    I'd find it necessary to have a distinction between global functions and object methods, because otherwise you wouldn't be able to access typically-used functions if it is redefined in your class, which is supposedly common.

    Of course, that's just my idea of what I'd do - what would you do?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  2. #2
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd make it C# like

  3. #3
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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.

  5. #5
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    PHP Code:
    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.
    PHP Code:
    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;
      } 


  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    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?)

    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.

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    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
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DeathShadow
    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.
    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:
    PHP Code:
    class Someclass{
        protected 
    $Database
        
    public function __Construct(PDO $this->Database){}

    That'd be better, in my opinion, than:
    PHP Code:
    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.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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:

    PHP Code:
    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!

  11. #11
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

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

    Then you'll like this recent addition.
    Salathe
    Software Developer and PHP Manual Author.

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:

    Quote Originally Posted by Salathe View Post
    Then you'll like this recent addition.
    I do, I do, I do Thanks for pointing it out
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  13. #13
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jake Arkinstall View Post
    I'd have to ask why, if you hate PHP and C-syntax so much, you even bother with PHP in the first place?
    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.

    Quote Originally Posted by Raffles View Post
    Use dot notation like in JavaScript.
    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:

    Quote Originally Posted by ScallioXTX View Post
    I don't really see the need for starting each variable with a $
    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/li.../l-clear-code/

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DS
    I mean seriously, try to make a self-recursive btree using PHP, you quickly find how PATHETIC it's object model is.
    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.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #15
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

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

    Instead of this

    PHP Code:
    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);
    // ...


  16. #16
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Sutton, Surrey
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get really annyed with eople who want to change the language just so that they can type in fewer characters. They think it would make them more efficient, but they are totally missing the point - program code is designed to the read by humans more than it is to be executed by a computer, so making code MORE readable instead of LESS readable shoud be the goal. My first language was COBOL, so I know about reading and writing verbose code. I also did some assembler, so I also know abut reading/writing code that is nothing but short symbols.

    My biggest peeve with PHP is with function braces. I don't like having '}' as the end marker for every single function. I much prefer the COBOL syntax where every function (or 'verb' in COBOL) has its own 'end' marker. Thus IF would have ENDIF, SWITCH would have ENDSWITCH, WHILE would have ENDWHILE, etc. This would solve the current problem where you have a missing '}' in your code, and the compiler can't report the error until it gets to the end of the file. How long does it take to work out exactly where the problem lies? With a proper end marker it could detect the problem sooner and report it in the correct place.

    My second biggest peeve is the difference between '=' (assignment) and '==' (test for equality). How many people have been caught out writing 'if ($a = $b)' instead of 'if ($a == $b)'? If the compiler writer cannot work out if the '=' symbol is being used within a condition or not then he shouldn't be writing compilers.

  17. #17
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, PHP does offer certain alternative syntax.

    As for equals - I like it. There are 3 equals variations, assignment (=), loose comparison (==) and strict comparison (===). All of these have their uses, even in an if statement.

    For example, statements which assign values and check them at the same time, for example:
    PHP Code:
    while($row $Query->Next()){ 
    where $Query->Next is a method to retrieve the next row. When the row is up, it returns false and therefore the loop terminates.

    Another example:
    PHP Code:
    if(false !== ($Position strpos(....))){ 
    So I like the C-style approach to those operators.

    I do agree with joebert about the + operator. The only place I could see a downfall is if two strings are numerical - how would the parser know what to do?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  18. #18
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony Marston View Post
    My second biggest peeve is the difference between '=' (assignment) and '==' (test for equality). How many people have been caught out writing 'if ($a = $b)' instead of 'if ($a == $b)'?
    I used to think that way when I was coming from other languages to C syntax two decades ago, and felt that way again a decade ago when I started using PHP.

    In the case of all C syntax languages there is a functional difference between them that you can't trust a compiler to do. You will realize this the moment you start dealing with returned values from functions and explicit exit values.

    For example, the PDOStatement object has a FETCH method. This method returns an array consisting of a result row, or false if no more records are present.

    The assignment operator (=) can be used then in your while:

    Code:
    while ($item=$qHandle->fetch()) {
    	echo $item['name'],'<br />';
    }
    If you made = only behave as == inside conditionals, you'd end up having to code that:

    Code:
    $item=$qHandle->fetch();
    while ($item!=false) {
    	echo $item['name'],'<br />';
    	$item=$qHandle->fetch();
    }
    So there is a legitimate reason for = to always be an assignment operator that returns the result as a conditional. For your consideration:

    $a=1;
    $b=false;
    if ($a=$b) { echo 'Test'; } else echo $a;
    /* echo's out 0 */

    Why does it output zero? because $a was assigned to the value of B, false, zero... The 'test' echo will never run becuase $b is false, the value of the assignment is what the if statement checks against. change $b to true, and it will echo out 'test'.

    === is also important, especially in PHP as opposed to languages like C which have strict typecasting.

    Consider this:

    $t=0;
    if ($t==false) echo '0 = generic false<br />';
    if ($t===false) echo '0 = specific false<br />';
    /* second IF will not fire */

    $t=false;
    if ($t==false) echo 'false = generic false<br />';
    if ($t===false) echo 'false = specific false<br />';
    /* both IF will fire */

    A specific comparison "===" of zero to false is always false, a generic "==" comparison of zero to false is always true... While PHP lacks strict typecasting it does track type silently in the background. This is often important if you have functions that can return zero OR false. Without strict typecasting this is the only way to differentiate zero, false, and empty string, an empty array, or null apart from each-other.

    Again, something that without strict typecasting there's no way for the INTERPRETER to do.

    Quote Originally Posted by Tony Marston View Post
    If the compiler writer cannot work out if the '=' symbol is being used within a condition or not then he shouldn't be writing compilers.
    INTERPRETER my good man, INTERPRETER. PHP is an INTERPRETED language, not a compiled one.

    I think that's where a lot of the attitude on things like that comes from, people keep thinking about php like it was a compiled language - it isn't, and interpreted languages need different optimizations to perform well. See the difference between interpreted line numbered basic and compiled basic. Line numbers, differentiating strings from floats using $ and forcing one digit variable names made interpreted basic remarkably fast for an interpreted language under extreme memory constraints. More modern line-numberless basic with long variable names means building a symbol table, having a pre-bytecode compiler, manually marking entry points... You wouldn't be able to do all that in 8 to 12k of ROM with 4k of RAM.

    Many of the things people list as PHP's strengths (untyped variables, custom array indexes) are also a weakness that resulted in many of the more unusual language syntax decisions.

  19. #19
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    I really dislike all the suggestions for shorthand code. Shorthand is bad. Replacing current language constructs such as $this with one character make for incredibly hard to read code for anyone looking at it. Especially when they would sometimes see the short hand and sometimes see the long hand. What would happen anyway is that someone would write an article showing that one was 0.0000000002ms faster and that would become the convention (see single quotes).

    Look at perl's lovely incomprehensible two letter function names. Shorthand is bad. It makes the language more difficult to learn.

    (xkcd 386 applies, of course)

    My biggest gripe with PHP is as others have said, inconsistent arguments along with inconsistent function names "strpos()" and "str_replace()" of course base64_encode() and urlencode() are equally annoying. Seriously they need to just make everything work without underscores and it would fix it.

  20. #20
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony Marston View Post
    My biggest peeve with PHP is with function braces. I don't like having '}' as the end marker for every single function. I much prefer the COBOL syntax where every function (or 'verb' in COBOL) has its own 'end' marker. Thus IF would have ENDIF, SWITCH would have ENDSWITCH, WHILE would have ENDWHILE, etc. This would solve the current problem where you have a missing '}' in your code, and the compiler can't report the error until it gets to the end of the file. How long does it take to work out exactly where the problem lies? With a proper end marker it could detect the problem sooner and report it in the correct place.
    Already in for the control structures (if, while, for etc.) : http://www.php.net/manual/en/control...ive-syntax.php which is very usefull when using php as a template language.

  21. #21
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by deathshadow60
    What, jquery wasn't bad enough for flushing javascript down the drain, now you want to turn PHP into L33T?
    Just awesome, someone had to say it.

    You guys covered the primary thing that bothers me ->. I would like to replace that with a single character and I would be mostly happy. Perhaps there are other things but that is primarily the one I constantly want to change.

    The other thing I would like to see that isn't syntax specific but feature is named parameters like python.

    I see where you some of you are coming from with self:: to access static methods. However, I don't really use static methods and properties all that often for that really to be an issue for me.

    None the less, going back to my initial response dot notion would make me very happy. Most of my assignments tend to require transitioning between JavScript and PHP. So having a similar way to access methods and properties would result in less stupid little syntax errors such as; using -> in JS or . in PHP.

    I think its really easy to take this to far though. There are really only a couple of things that I think would be beneficial to change. Once you start modifying everything you end up with what looks to be a mess. Especially when you start abbreviating things and using characters to denote access. Although that may seem like a good idea its going to make everything more difficult to read and understand. That is probably especially true for beginners.

    One thing someone did mention perhaps not in this thread is standardizing the function signatures. At least to the point where if two functions accept a needle and a haystack the signature is the same. Although, named parameters could possibly fix that issue.
    The only code I hate more than my own is everyone else's.

  22. #22
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So the general feeling is that the string functions (and array functions etc) need rewriting. Unfortunately that would break backwards compatibility - so my suggestion would be an entirely new library.

    I'd like strings etc to act as native objects.:
    PHP Code:
    $something 'Hello world';
    $something $something->replace('w''W'); 
    And of course a static version:
    PHP Code:
    $something string::replace('Hello world''w''W'); 
    Off Topic:

    Quote Originally Posted by deathshadow60 View Post
    You wouldn't be able to do all that in 8 to 12k of ROM with 4k of RAM.
    Well anyone who could deserves a medal or something. But it's entirely irrelevant; average servers have giga-terabytes of storage and gigabytes of RAM, not to mention multiple processing cores. The 20th century, you gotta love it
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  23. #23
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jake Arkinstall View Post
    So the general feeling is that the string functions (and array functions etc) need rewriting. Unfortunately that would break backwards compatibility - so my suggestion would be an entirely new library.

    I'd like strings etc to act as native objects.:
    PHP Code:
    $something 'Hello world';
    $something $something->replace('w''W'); 
    I like this idea too. For arrays it would also be handy (which you already wrote ):

    PHP Code:
    $arr = [1"abc"];
    $arr.sort();
    echo 
    $arr.pop(); 

  24. #24
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't like many of these suggestions really, mainly because they are all trying to turn PHP into something it isn't. Why make PHP like JavaScript? What's the point in using Strings as objects or whatever, just because another language does it? It'd turn PHP into some kind of franken-language, borrowing snippets from everywhere else, and it's just totally unnecessary.

    My only real issue with PHP as it is is the inconsistency in function naming, but I think that's more of a problem in people's heads than a real problem - I certainly haven't found it any harder to learn PHP's function names than any other language. The fact that most of you moaning about it are able to quote examples from the top of your head shows that it clearly isn't a problem memorising the names!

    A decent IDE solves most of that issue anyway, prompting for parameters etc.

    I like '->' for accessing properties/methods, I like $this, I like . as concatenate...

    The only really sensible suggestion of being able dereference arrays when being returned by a function eg function_name()[3] looks like it has already been implemented anyway.

  25. #25
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oh, and I like curly braces - there is no problem seeing what is missing if code is formatted properly, or you use an IDE with bracket highlighting - problem solved. I comment most of my closing braces anyway with what they relate to - eg }//if, }//foreach etc


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •