Giter Site home page Giter Site logo

nextjs-use-php's Introduction

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.

nextjs-use-php's People

Contributors

onatcer avatar bufferhead-code avatar szebest avatar tholder avatar

Stargazers

Bayu Rifki Alghifari avatar Dakyum Yeo avatar  avatar Lluís Masdeu avatar Огњен Јовановић avatar  avatar  avatar Angel avatar Constantin Graf avatar  avatar 타스씨 avatar iZucken avatar Mekel Ilyasa avatar Jason avatar Carlo avatar EvanLong avatar vincentchan avatar Daniel Neslukhovskiy avatar asuka avatar  avatar Hassan Kerdash avatar Łukau ŁK | FullStack Developer avatar steve avatar  avatar Thomas Lekanger avatar Dominic Bachmann avatar nick avatar Iqbal Mohammad Abdul Ghoni avatar react#1507 avatar  avatar Juan Urquiza avatar YongChan Cho avatar Keenwon avatar Pho Thin Maung avatar İ. Görkem Çoban avatar Lucky Kusuma avatar  avatar Bohdan avatar Selemondev  avatar nito avatar Kian Brose avatar MasihGhaznavi avatar Maxim Nam avatar  avatar Kevin Firko avatar henry-yu-lb avatar marcinm-wskz avatar I Putu Agus Wahyu Dupayana avatar Grafaffel avatar  avatar  avatar Shubham Tiwari avatar Petr Kolář avatar Batuhan Göksu avatar nonn_app avatar halfstack avatar len avatar Cony avatar Media Explorer avatar ᡥᠠᡳᡤᡳᠶᠠ ᡥᠠᠯᠠ·ᠨᡝᡴᠣ 猫 avatar Khoa Hoang - KMS Healthcare avatar Alexey Volkov avatar Nazar Kornienko avatar Tobias Deekens avatar Tobz avatar Jesse Niininen avatar  avatar Victor Fedorenko avatar Abiria avatar Adrian Kuklinski avatar Karusa avatar Sergio Gómez avatar Saeed Vakili avatar MH Shifat avatar whchi avatar Richard Unterberg avatar Thomas Caron avatar Ben Faerber avatar Vitor avatar Jeffrey avatar sugar avatar sxsx欧克 avatar  avatar muhammad hanif ramadhani avatar  avatar  avatar Muel avatar Bohdan Sviripa avatar  avatar EF_fadli avatar Rizqi Alaudin Syahrendra avatar Yo avatar Aalaap Ghag avatar Robi Irhamni avatar Leonardo Silva avatar Muhamad Ari Sawali avatar Jian Jye avatar Kayac Hello avatar Reyhan M avatar Cintara Surya Elidanto avatar

Watchers

Romack Natividad avatar Calvin Reibenspieß avatar  avatar  avatar nito avatar Julia Abrams avatar

nextjs-use-php's Issues

🕒 Introducing the 'Time Travel Debugging' Feature - Because Why Not? 🕒

Dear Time Lords of 'Next.js Use PHP',

I've recently embarked on a journey with your framework, and let me just say, it's been... a unique experience. But, I've noticed a glaring omission that's practically a deal-breaker. I'm shocked, nay, appalled, that there's no built-in time travel functionality. How could this be overlooked?

Here's why it's absolutely essential:

  1. Debugging in the Past: Who needs modern tools when you can just go back to the moment your code was written and ask your past self what they were thinking? I mean, come on, it's just common sense.

  2. Future-Proofing: I need to know if my code will still be hip and happening in the year 3000. What if JavaScript is replaced by telepathic coding? We must prepare for such eventualities!

  3. Temporal Styling: Style trends change. I need to ensure my CSS is just as snazzy in the Renaissance as it is in the distant future.

As a forward-thinking (and backward-thinking) developer, I propose the immediate implementation of a 'Temporal Debugging' feature. It's clearly what the industry has been missing.

Php 4.2 support

Hello, is it possible to enable php 4.2 support please, I would need it to build a cutting next old generation a.i. doped saas

Unexpected keyword or identifier for print

I'm trying to implement this on my existing project but i get this error:

Screenshot 2024-01-04 at 11 35 48

How do i enable 'use php' directive in my existing project?

Does this really work or its a kind of a joke?
Can i run cURL in here?
Can i use this in my production app hosted on vercel?

MERGE THIS REPO WITH NEXT.JS UPSTREAM

As a human🤗, not AI🤖, this project is very helpful✨ to job creation👨‍💻 by making code💻 difficult to maintain🔧. This code 💻 should be added to the next.js official repository 👽

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.