PHP:为什么不在类中识别变量PHPSESSID?

As the title says,, I want to know because it does not recognize the $ sessionID variable within the class DB_Functions.

When I check the table, all fields except the variable sessionID stored.

<?php

session_start();
$sessionID = $_COOKIE['PHPSESSID'];

class DB_Functions {
....
....
....

public function insertItemToCart($dataMovieToInsertCart) {
        $precio = $dataMovieToInsertCart['precioMovie'];
        $id =  $dataMovieToInsertCart['claveMovie'];

        $query = "INSERT INTO carrito (session_carrito,id_pelicula,precio_pelicula) VALUES('$sessionID','$id','$precio')";
        $result = mysql_query($query) or die (mysql_error());

        if ($result) {
            return true;
        } else {
            return false;
        }
    }

}
?>

two way fix:

1.) use global keyword inside the function to catch up with global variables which are not available inside function scope

2.) if its only the case of session_id, use session_id() function inside function.

eg for 1:

global $sessionID;
$id =  $dataMovieToInsertCart['claveMovie'];
$query = "INSERT INTO carrito (session_carrito,id_pelicula,precio_pelicula) VALUES('$sessionID','$id','$precio')";