Custom PHP interpretor? [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 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! ;)

Related

For Shopify, I'm conflicted between learning PHP or Ruby [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 4 years ago.
Improve this question
I'm not sure how to phrase this question that won't get me to hate from you guys but I'm giving it a go. I'm aware of the basic syntax and logic of programming like if statement, variable, type of strings, etc (purely basic) though I'm a little more familiar with PHP.
Now I wanna learn Shopify development, though they don't have direct support for PHP but one can build Shopify apps on Laravel too (so I've heard).
I'm very conflicted between learning either PHP or Ruby because it'll be almost all the same for me and ofcourse I don't wanna learn it just for Shopify.
Anyways, your input will be appreciated.
It really makes no difference. There. I said it. Shopify is so agnostic to the tech stack you choose, it is up to you to decide what works for you.
PHP, Ruby, Python, Javascript, heck even C# all work the same for making Shopify Apps. Your preference matters. If you feel comfortable with PHP, use it! There is zero obligation to use Ruby just because Shopify uses it.
In fact, Shopify is now so agnostic, their GraphQL based API for Apps eliminates all "my stack beats your stack" crap to nothing. These days, you can safely just focus on wiring it up to work, without offending anyone. Make an HTTPS call to an endpoint, get back data. Process it, act on it, show stuff off. Simple. No need to worry about how you do that. All scripting languages do it.
I would choose Ruby since that is the native support for, and later PHP if that is necessary in another project.

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

Procedural PHP vs Object Oriented PHP [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 fairly new to PHP (you just have to see some of my previous/recent posts!). I have done a lot of my learning by studying other people's frameworks and attempting to rewrite them for my own purpose.
Out of the examples of code I have seen, it seems about 50/50 Procedural to OOP. My question is not which is better, but when should I consider using OOP over Procedural?
By the way, I don't want to encourage an open discussion of personal opinions as to why one should be used above the other. I am fully aware, after researching, that some people just prefer to use one or the other. I am after a legitimate reason as to what would encourage me to use one over the other and in what situations.
I have also read through a few different (but similar) questions on the subject, but they seem to be flagged as not constructive because it starts a debate. I don't want this, I am on a Q&A site as I am looking for an answer, not an argument.
Even thou it is 2014, you are still allowed to wash your dishes by hand, communicate with all your friends only in person, landline phone calls or letters send by the local postal service.
And you might feel incredibly well doing so.
But if you try to host a lot of dinner parties for a lot of people and organise important projects with a lot of people from remote destinations, having hard deadlines, you might consider getting a modern dishwasching machine and a smartphone.
Same goes for OOP vs. procedual. If you are just adding a tiny piece of functionality (display the current date, echo a random hash string) on your wordpress weblog: Go procedual.
If you are writing a tiny tool that does something you need to get done, if you are writing a tiny cron job batch script in PHP or if you are just fooling arround - do as you like.
But if you plan to develop sustainable, maintainable, testable, reusable, quality software that has a lot of features you should at least use OOP. Because it is bloody 2014.
OOP will enable you to blackbox and whitebox test units of your code seperately. It will enable you to not only efficiently reuse libraries and modules written by others but alos enable you to produce modules and libraris that can be reused by others.

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.

PHP4 to PHP5 Migration [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 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).

Categories