How do I delete a function body in a php class using the sed or awk or grep commands?

how to delete the method body in a class using the sed or awk or grep commands

sample source file: demo.php

<?php
class Demo {
    private $a;
}

of course, there may be many methods in the class.

Aug.20,2021

sed ':a;N;$!ba;s/public.*/}/' demo.php

modify the source file directly:

sed -i ':a;N;$!ba;s/public.*/}/' demo.php
Menu