Posted By

chrisaiv on 11/29/09


Tagged

php


Versions (?)

PHP: How PHP is inconsistent


 / Published in: PHP
 

  1. <?php
  2. /**********************
  3. Class Example
  4. **********************/
  5. class Car{
  6. //Inconsistency with access modifiers
  7. var $tire_count = 4;
  8. public $door_count = 2;
  9.  
  10. function num_of_tires(){
  11. //You need to explicitely use $ to assign variables but then don't use them for reference
  12. $string = "This " . get_class($this) . " has " . $this->tire_count . " tires";
  13. return $string . "<br />";
  14. }
  15. }
  16.  
  17. $my_car = new Car();
  18. echo $my_car->tire_count . " :: " . $my_car->door_count . "<br />";
  19. echo $my_car->num_of_tires();
  20.  
  21. /**********************
  22. Global Variable Example
  23. **********************/
  24. //No use of var or public
  25. $tires = 4;
  26. $doors = 2;
  27.  
  28. echo $tires . " :: " . $doors . "<br />";
  29. //echo $this->$cat;
  30.  
  31. //Reference looks ugly
  32. $reference =& $tires;
  33. echo "Reference before: " . $reference . " || ";
  34. $tires = 2;
  35. echo "Reference after: " . $reference;
  36. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MMDeveloper on November 30, 2009

the 'var' modifier is deprecated and therefor a moot subject. The global variables don't need a modifier because you cant have a private global variable, they're global. The references are C style pointers. Your example inside the numoftires function just makes no sense. It's just the syntactical differences between languages. Just because one language does things a little differently than the only language you know, doesn't make it bad. Just keep in mind that the php language was modeled after C, which makes it one of the fastest server-side web languages.

Posted By: chrisaiv on December 2, 2009

WoW! I'm just amazed that people actually read what I write.

MMDeveloper, all very good points, I'm just spoiled by Ruby and Python.

Thanks once again for taking the time to explain the story of PHP.

Posted By: AKtivX on December 22, 2009

I recall a University professor explaining to me how in his completely biased opinion, a truly professional programmer/developer or software engineer would never waste their time or the time of their colleagues by complaining about the shortcomings of a given language whatever it may be, rather, as a professional, they would be more focused on determining the proper tool required to most efficiently complete the task at hand. All languages have shortcomings and inconsistencies without exception, so in following this professors teachings, if using the PHP language will get the job done as specified in the requirements, and get it done faster, easier, and much more efficiently than any other language, why would I want to use anything other than PHP for this task? The Professor in question was at that time an instructor in Computer science software engineering program at the same university once attended by Rasmus Lerdorf, the original architect of the PHP scripting language. And finally, last I checked, PHP is licensed under an open source license, so the source code is freely available. If you dont like the way the PHP engine functions, feel free to check out the source code from the repository, and fix the problem . No one is stopping you at all.

Posted By: chrisaiv on December 23, 2009

AKtivX: Thank you for sharing your opinion, I always appreciate to hear other points of views and thoughts on computer languages.

That said, I respectfully disagree that it is a waste of time to identify the shortcomings of a given computer language. In fact, by identifying the shortcomings, you help others understand why they might prefer a different solution.

I use Snipplr not only as an opportunity to give away my code but also share my discoveries as a programmer. As you can tell from my code timeline, I'm doing a lot with PHP right now and am sharing a few of my lessons. Unfortunately the project I'm working on does not allow me to choose the computer language I see best fit so instead I've got to live with what I have.

Posted By: AKtivX on December 24, 2009

chrisaiv: Point taken, and a good point at that. I guess I am more than a little weary of the "my language is better than your language" debate that I guess has been ongoing for some time. Having said that, you make some very good points and it appears that I did not fully think things through where it is now obvious I should have looked at the things with a much more open perspective. You are absolutely correct that this is a good place to share our discoveries, and I thank you for sharing your observations. But I still believe in this professors teachings.... I still feel that choosing and using the proper tool for the job can be quite beneficial and a saver of both time and energy, if and when it is possible to do so. Regards

You need to login to post a comment.