PHP4 to PHP5 Migration [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What are some good steps to follow for a smooth migration from PHP4 to PHP5. What are some types of code that are likely to break?

I also once worked on an app which used PHP4's XML support quite heavily, and would have required quite a bit of work to move to PHP5.
One of the other significant changes I was looking at at the time was the change of the default handling of function parameters. In PHP4 if I remember, they were pass-by-copy unless you specified otherwise, but in PHP5 is changed to pass-by-reference by default. In well written code, that probably won't make a big difference to you, but it could certainly cause problems.
I think one other thing I found changed is that objects are no longer allowed to overwrite their 'this' field. I would say that was a really bad idea to begin with (and I think it may have not been an intentional feature in PHP4), but I certainly found a few parts of our system that relied on it.
Hope some of that helps.

The best advice I could give anyone working with PHP4 is this:
error_reporting( E_ALL );
It pretty much will tell you exactly what you need to do.

We had an app that relied heavily on the PHP 4 XML DOM functions and it required a lot of retooling to change over PHP 5.
Beyond that most changes were improvements to things like error handling (to take advantage of exceptions) and PHP Classes.

OOP is one of the largest differences. It won't break as the PHP4 and PHP5 OOP styles are interchangeable but I'd reccommend taking advantage of PHP5's new OOP styles. It's not a huge amount of work to convert your existing classes to PHP5 and it does give you some extra magical methods that may help solve some existing hacks (I remember having a near useless __toString equivalent method in most classes).

Related

Is a compare between PHP and NodeJS worth? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I start this topic saying that I use PHP since 2014 and I'm experienced with it, but recently (yesterday) I started to give a look to NodeJS.
Node is growing fast and it's been used by a lot of web-services.
I started using it yesterday, but I found it less "beginner-user friendly" than PHP.
I'm not saying this as a beginner in computer programming, but as a Node-beginner.
What is your opinion?
Is it worth knowing both languages?
Is it worth knowing both languages ?
If you come from php development, learning node is a great idea.
It ll teach you in a soft way the concurrent programming pattern, and also event/stream programming,
it will lead you to face problems regarding the underlying OS in a soft way.
All sort of stuff that PHP greatly solves for you right out of the box and which you never think about.
Node will also give you the impression of a bigger playground to explore.
But, if you want to be productive when it s about building website, i believe PHP is better.
On the other hand, if you are looking for performance, node may be better, but true performance comes with compiled languages like GO, not scripted languages.
Finally, if php was not plumbed by all those damn heavy javaesque framework, it would be a really nice environment with a good trade off between speed and complexity.
Node gives you speed, but it comes with a price about the complexity which can be very costly.
As a beginner of both language i noted the following advantages of both languages
PHP
Mixing code with content
Deep code base
No client app needed
SQL
Speed of coding
NodeJs
Separating concerns
Newer code means more modern features
Service calls are thinner than HTML-fat PHP calls
JSON
Raw speed
You can read full article Here

PHP style guide / coding standards: which one to apply? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am trying to implement and follow some coding standards in my PHP code.
I did read a few question already asked here but I think an attempt to centralise information might help others like me. I found a few resources (6 until now):
PSR: PHP Framework Interop Group
Wordpress PHP coding standards
framework.zend.com/manual/1.12/en/coding-standard.html (I am not
allowed to post more than 2 links yet)
pear.php.net/manual/en/standards.php
The latter has a tool to help comply with it, CodeSniffer, although you can configure it to check for any standards.
drupal.org/coding-standards
https://www.codeigniter.com/user_guide/general/styleguide.html
Although they do seem to set a common ground, they do show conflicting info, for instance, the first two links, Wordpress recommends to have a space after opening parenthesis and before closing one, while PHP-FIG recommends the opposite: if ( $a === 0 ) v if ($a === 0)
Codeigniter style guide basically contradicts everything in the Wordpress guide...
Are there any other resources that might have a higher authority on the matter?
What are others using, or does it even matter to follow a "standard" if it is contradicted by another?
Ultimately the way you format your code I think will come down to these questions...
Who looks at the code? Just you?
Stick with what you feel comfortable and feels more readable for you. There are very few projects where everyone actually adheres to the full coding standards.
Will anyone else in the future look at the code?
If so use the most common standard. You feel comfortable with.
Are you building/coding off an existing codebase?
Try to match their existing standards.
I am actually working off the 'ownCloud' core for my current projects. They have this huge guide of how to format their code. NOBODY who contributes follows it. So the code looks horrendous and is so inconsistent. Any portions of code I have to work with I always reformat to my taste since there is no standards police.
Actually this question is going to get closed because the answers will be opinion based and so is mine:
I would not go by Wordpress, the code of that project is... not good. WP is for sure not popular because of it's "superior" code and architecture. If you want a blog, take it, if you want good examples of development, architecture and best practice - stay far away from it.
PEAR is just outdated IMHO. And it is not just pear that has a code sniffer, phpcs is a generic tool:
https://github.com/squizlabs/PHP_CodeSniffer
Good projects come with a ruleset for their conventions. The sniffer itself comes bundled with a few rulesets like PEAR and I think PSR as well.
The PSR standard is a pretty good one to use except the never ending tab vs space discussion. I personally think spaces for indention over tabs is idiotic because that's exactly what tabs are thought for and virtually every editor can configure the displayed tab size to match X spaces.
So I would recommend the PSR standard.
But I use whatever standard the project I'm working on is using. If I work on CakePHP I use their coding standard, if I have to work on Wordpress (please no!), I'll use theirs. For my own projects I go for PSR.
I would recommend you to read this book in addition:
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
It's using Java for the examples but the language doesn't really matter here.
Whatever standard you use, I'm happy you think about writing clean code and that you want to make sure you have a standard! Many "developers" just don't care and write a huge mess.

Custom PHP interpretor? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Compared to some languages, PHP's syntax is a little bit long (e.g. in java calling the method of an an object is done with a period ( . ) instead of phps (->) ).
I have always wanted to write my own language but I'm only a first year bachelors student and am in no way knowledgeable enough to write a parser that converts something to byte code for the Java VM or something.
So instead I'm thinking of writing a parser in PHP that converts my syntax into PHP code then runs that using regex and stuff.
Reasons for that being:
PHP is a stable language for web sites (my syntax will be suited towards web developers)
I already know PHP at a professional level (or at least I think I do)
I have already seen an implementation of something similar: http://tetraboy.com/lolcode/lol_core.phps
This converts LolCode into PHP. And I know its just a joke but still it has been done
So since I have proof that its possible.
My question is:
Could I actually make something that I could use for future projects? e.g. Can I get it to be as fast or almost as fast as PHP is?
I'm going to give it a try either way just for the purposes of learning a little bit more about PHP and how languages are put together, but I'm wondering if I could actually turn the end result into something worth a damn.
If anything, this is a very fun learning project.
There are others that had the same idea with other languages. For instance, take a look at CoffeeScript, which is basically the same idea but for Javascript.
You can make this work, but you'll have to take into consideration the conversion process. If you're looking for performance you do not want this to be done realtime on each request. Because adding layers of complexity will simply slow down your code. Even if it's just by the tiniest bit. To rememdy this CoffeeScript offers a command line 'compiler' for pre-compilation but also allows for a lazy loading situation - which works nicely for development purposes. Such a setup might work for you aswell.
You'll want to look at PHP_LexerGenerator and PHP_ParserGenerator for implementing your parser. Even if the latter is no longer maintained :)
Good luck! ;)

PHP or Lift framework for a web application? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm currently developing a web application using PHP, but I'm considering developing the web application using the lift framework instead, because twitter and foursquare have implemented it. I know a few benefits using lift/Scala but, could you guys mention some benefits compared to PHP?
Many thanks
Resmus Lerdorf, the inventor of PHP, once said with regards to foursqaure (build with scala/lift) that it's the first site for a long time that doesn't have a single security hole he could find.
If you're having trouble enumerating the reasons why you'd use scala/lift over PHP, you'll probably want to stick with PHP. PHP is a far more mature and supported platform - oodles of documentation, huge community, tons of tools and libraries.
Scala is a great language, but the primary reason it's being used by Twitter and Foursquare is it's ability to work with enormous sets of data on a horizontally scaled architecture. These are very specific problems for these companies, and Scala was chosen for this purpose very deliberately.
As someone who has recently begun learning Scala, the community and documentation is minute compared to PHP's. Especially where Lift is concerned. And things like IDE support is still in it's early stages.
There's really no way to compare the two technologies (very different approaches). If want to use Scala, use it, but you'll probably be investing more time and energy if you're not already proficient (also, some background in Java doesn't hurt). PHP is just PHP, it's so easy to just pick up and use.
If you ask such a question you'd better stay with PHP. Once your project becomes more and more complex and you are fed up with PHP limitations the question will disappear on its own.
But Lift does not have to be the framework of your choice.
You should consider anything except PHP a good language for web applications, but Scala is a pretty excellent one, although it will change the way you think about programming as a whole. Some people can't handle that, so be warned.
PHP advantages:
Is installed even on the cheapest "5ยข-a-month" webhoster.
PHP disadvantages:
The libraries are not stable and change every now and then, often without notice.
The whole language is buggy and generally doesn't work as a sane person would expect.
The documentation is unusable, sometimes wrong, sometimes only understandable with the user supplied usage examples (which are often wrong or not optimal, too).
No quick way to see the implementation of some language-supplied code.
The API is one big mess ... this shouldn't be called API, it should be called MCOBRIM: Messy Collection of Buggy, Random and Ill-named Methods.

which unit-test framework for PHP: simpletest, phpunit or? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a big fan of simpletest because it's what I know. It has excellent support for mocking and web-testing.
But I'm always scared of stagnating so any compelling arguments to switch would be appreciated.
I don't think either is going away anytime soon. Simpletest is maintained by a small, but involved group of people.
PHPUnit seems to have a bigger userbase, which may count as an argument for switching. I'm quite happy with Simpletest though.
I haven't used SimpleTest myself, so I can't say much in a way of comparison. Just by observation though, the PHPUnit syntax seems much more verbose.
The PHPUnit Manual is a great source of documentation, and covers most areas of the framework. My only complaint about the manual is that some areas lack detail.
My main reason for using PHPUnit over SimpleTest is that it has great Phing integration.
I just answered a similar question and added that there's phpt. phpt also integrates into PHPUnit.
I would recommend behat (+mink)
http://behat.org/
It's functional/integrational testing, but it covers much more code in much less time...
P.S. You can, actually, use it to write unit/tests, but it's a bit of overkill...
I don't know if you'd want to switch per-se, but I like phpt for testing small libraries of code or getting tests out the door sooner rather than later, if there are none in an existing library that needs to be tested.
phpt won't scale as well as Simpletest, but again, the right tool for the right job. Take a look at this article for an in-depth discussion to get you ramped up.

Categories