TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Write PHP Code Within Next.js Components

112 pointsby 0natcerover 1 year ago

29 comments

nperezover 1 year ago
For those not in on the origin of the joke, Next.js introduced &quot;server actions&quot; which became a huge meme &#x2F; debate topic on Twitter - for example, <a href="https:&#x2F;&#x2F;twitter.com&#x2F;peer_rich&#x2F;status&#x2F;1717609270475194466" rel="nofollow noreferrer">https:&#x2F;&#x2F;twitter.com&#x2F;peer_rich&#x2F;status&#x2F;1717609270475194466</a><p>This is presumably inspired by all of the people saying Next is turning into PHP.
评论 #38121726 未加载
bottlepalmover 1 year ago
It&#x27;s funny, but all you see here and on Twitter are cheap shot one liners, many of these people have never even used Next.js.<p>I find server actions combined with RSC to be incredibly useful and powerful. Easily define and call a type safe function from client to server with zero overhead. No API boilerplate, fetch, tRPC anything.. You just define a function and call it, very nice. Type safety, code completion, refactoring works across client&#x2F;server, all that.<p>Of course the examples of server side code in client side function handlers are just that, examples, not the suggested way to use server actions. You can write super hacky &#x27;bad&#x27; code in every language. Server actions are best defined in their own file of course.<p>Not sure why it&#x27;s being compared to PHP so hard as PHP is a backend only SSR framework, while Next seamlessly transfers the components&#x2F;code&#x2F;state to the client so you can continue re-rendering with the same framework and language client side as you used server side for SSR. PHP could never do that.<p>The closest thing to server actions in PHP is Livewire, which was never a standard part of PHP and not unique to PHP either. Most PHP apps just use normal JS libraries for interfacing with the server.
评论 #38121795 未加载
评论 #38121083 未加载
评论 #38123813 未加载
评论 #38121997 未加载
评论 #38121131 未加载
评论 #38122292 未加载
dgorgesover 1 year ago
&gt; I hope I don&#x27;t have to say this but: If you even in the slightest consider to use this in any application at all you are an absolute madman and and should be locked out of the internet for the rest of your life, I hope you find some other fun activity, maybe gardening or woodwork.
评论 #38123560 未加载
评论 #38121240 未加载
timackover 1 year ago
Every day we stray further from God&#x27;s light.
评论 #38121209 未加载
评论 #38120790 未加载
CSSerover 1 year ago
I think part of what makes these recent gags so funny to me is that it illustrates how perilous mixing RSC with client code feels in practice. Worrying about teammates accidentally exposing environment variables was already bad enough. Debugging is now even more troublesome, and for what? So we can use some XML-like syntax everywhere? React serves a purpose but this doesn&#x27;t feel like it. All these directives, the lookalike tree complexity, and overloading fetch just feels <i>wrong</i>.
评论 #38121311 未加载
评论 #38124613 未加载
droptablemainover 1 year ago
&quot;Your [engineers] were so preoccupied with whether or not they could that they didn&#x27;t stop to think if they should.&quot; - Ian Malcolm
_chimmy_chonga_over 1 year ago
They only ever asked themselves if they could, never if they should.
评论 #38120668 未加载
NorwegianDudeover 1 year ago
Any way I can remove the Next.js part? That would be perfect! Haha.
评论 #38121341 未加载
teaearlgraycoldover 1 year ago
I hope with enough joking around the Next.js team realizes they&#x27;ve made a horrible mistake.<p>What they <i>should</i> have done was include a convenient RPC framework in Next - not magic code-splitting and magic RPC code-gen built specifically for people that are too lazy to write two files for code ran in completely different environments.
评论 #38120975 未加载
thinkingkongover 1 year ago
Moving past the <i>excellent</i> joke.<p>The problem I see with Next has nothing to do with re-visiting these concepts, and almost everything to do with the examples. Flipping your mindset from “react is a framework for client side rendering” to “react is a dsl for building HTMl on the server” is a leap and it brings all this junk with it. I think thats how we get these parodies, and the “sql in a component” nonsense.<p>What <i>is</i> missing though is guidance on how to clearly separate these things. How do you do permissions, security model, clear separation of concerns, etc within nextjs in this new world? This is not new ground so the patterns should be pretty easy to describe. But thats missing and as a result, we do have people saying “no no. The process.exec call was a demo” without realizing that people are going to refer to that as a best practice.
评论 #38124164 未加载
评论 #38122872 未加载
mrspenceover 1 year ago
&quot;Yes this actually works. Trust me I wish it wouldn&#x27;t too.&quot;
stevebmarkover 1 year ago
My favorite part about this debate is that this is how Rails works, but Rails is worse. You intersperse raw database calls with your template code (`user.first_name`), and your templates kick off an untrackable amount of queries, and when you start nesting templates, you&#x27;ve lost all hope of app optimization.<p>RSC looks like it has some great potential. I really enjoy seeing these miss-the-point trolls that overlook existing technology issues.
aussieguy1234over 1 year ago
As much as I like PHP and JavaScript, as the README in this repo alludes to, this is cool concept but its not a good idea to actually use this.<p>Some of the worst code I&#x27;ve had to maintain are weird mixtures of PHP&#x2F;JS all in the one view file including where you have PHP generating JS&#x2F;interpolating in variables.<p>PHP as a templating language alone is actually pretty decent, but you need to keep the JavaScript separate to keep things clean.
评论 #38123976 未加载
ralmidaniover 1 year ago
Ironically, these days PHP has its act together - look at Laravel - better than most of the JS ecosystem does.<p>I don’t mind JS as a core language. Web Browser APIs are pretty awesome (with a few notable exceptions like IndexedDB). But the Node and SPA ecosystem is, speaking objectively, a dumpster fire.<p>We parody “enterprise” software, where vendors convince large companies to invest in over-engineered garbage.<p>Node, Express, React, Vue, etc. used to be for hipsters who wanted to cobble something together with maximum velocity and flexibility. But with them now in the big leagues, we’re seeing the same “enterprise” patterns emerge.<p>This is not an inevitable part of “growing up”; Python&#x2F;Django and Ruby&#x2F;Rails have been around for two decades, powered various unicorns, and are used at old-school multinational corporations as well as tech behemoths. But they have not fallen victim to the nonsense that plagues the JS ecosystem.<p>In fact, a lot of the JS ecosystem is now the worst of both worlds; you have over-engineered “solutions” combined with outrageous churn and zero sense of direction.
评论 #38123911 未加载
hyggetroldover 1 year ago
Looks nice but what would <i>really</i> take it to the next level is the ability to run Java but just JNI (everybody knows that&#x27;s the only useful part).
droptablemainover 1 year ago
Can confirm that it works with shell_exec as well.
评论 #38123841 未加载
rpmismsover 1 year ago
I may actually have a practical purpose for this. Yes, I could do the same thing with a simple API, but this is way funnier.
tantamanover 1 year ago
You think this is a joke but Meta&#x2F;Facebook has something similar for interop between XHP (<a href="https:&#x2F;&#x2F;github.com&#x2F;hhvm&#x2F;xhp-lib">https:&#x2F;&#x2F;github.com&#x2F;hhvm&#x2F;xhp-lib</a>) and React.
some_furryover 1 year ago
Thanks for this, I&#x27;m deploying it to production, stat
robover 1 year ago
As someone who loves PHP&#x2F;Laravel&#x2F;WordPress, don&#x27;t tempt me.<p>My WordPress plugin built with Next.js, integrated with Laravel, coming soon.
评论 #38121182 未加载
adhamsalamaover 1 year ago
I commented &#x27;When will they add &quot;use php&quot;?&#x27;, didn&#x27;t know a madlad actually did it.
byhemechiover 1 year ago
I am extremely tempted to write a vscode mode for this. I&#x27;ll let you all know if I survive
ulrischaover 1 year ago
Not only HTML in JS, now also PHP in it. How about also adding CSS?
CafeRacerover 1 year ago
This is exactly what I wanted but newer knew existed!
mirkodrummerover 1 year ago
meh not my cup of tea. Please let me know when “use gpt” will be generally available
frodowtfover 1 year ago
It&#x27;s time to stop.
leptonsover 1 year ago
Do I have to??
garymoonover 1 year ago
why?
loloquwowndueoover 1 year ago
Good lord. Why.