Skip to content
프로젝트

소개

React / Next.js 앱에서 PHP 코드를 바로 사용할 수 있습니다. "use php"를 사용합니다.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Next.js use php

[!NOTE] Check out solidtime - The modern Open Source Time-Tracker at solidtime.io

Use PHP right inside of your Next.js project. Just like use server (not really).

You can watch how i made it here

Youtube Video about how this project was made

You can use it in React Server Components just like this:

return (
    <button
        formAction={async () => {
            'use php'
            (new PDO('mysql:host=localhost:3306;dbname=public', 'root', 'root'))
                ->prepare("INSERT INTO Bookmarks (slug) VALUES (?)")
                ->execute(array('new'));
            }}>
        Insert Bookmark
    </button>
)

And if you want to it can even work with React Client Components

// actions.js
'use server'

export async function phpHelloWorld() {
    'use php'
    print "Hello from PHP";
}
// page.tsx
import {phpHelloWorld} from "../actions";

Yes this actually works. Trust me I wish it wouldn't too.

Build

You can build the implementation by

npm run build
npm run start

Open http://localhost:3000 with your browser to see the result.

If you want to try out the Database Example, you can use the docker-compose file provided in the repository. after docker-compose up -d you need to create the database and table you want to insert into manually.

Roadmap (Things that should be fixed but realistically it will never happen)

  • There is a probably a way to fix that nasty preprocess step with SWC Plugins which are still in Beta with Next.js and also I think they will switch builder anyways soon so what's the point really? But hey if anyone wants to do it feel free.
  • I guess there is some hacky way to make props binding possible.

Credits

Check out the original implementations by elnardu for C and Rust:

Disclaimer

I hope I don'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 madperson 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.

Self-Promo

If you enjoyed this project and want to see more silly web development projects, you can follow me on Twitter, Bluesky and Youtube.

관련 프로젝트 살펴보기

불러오는 중…