who define variable in function and use in class : i want create new variable in class by function:

    CLASS book{
    
       public function set($name){
          newvar($name);
       }
    }
    
    function newvar($str){
       ***????
       /// what is code for here***
    }

--------------------------
example:
    $x = new BOOK();
    $x->set('title');
    
    $x->title = 'jack';
    echo 'book title is: ' . $x->title;
    
    echo '<br>-----------------------------<br>';
    
    $x->set('writer');
    $x->writer = 'tom';
    echo 'book writer is: ' . $x->writer;


result:

    book title is jack;
    ----------------------------------
    book writer is tom;