Retrieve newly created Term tid I've created a PHP program outside Drupal that inserts Terms into my Drupal installation.

define('DRUPAL_DIR', __DIR__);

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel-&gt;boot();

require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';


$term = \Drupal\taxonomy\Entity\Term::create([
      'vid' =&gt; 'subject',
      'langcode' =&gt; 'en',
      'name' =&gt; 'Test af Tag',
      'description' =&gt; [
        'value' =&gt; '&lt;p&gt;My description.&lt;/p&gt;',
        'format' =&gt; 'full_html',
      ],
      'weight' =&gt; -1,
      'parent' =&gt; array(0),
])-&gt;save();

var_dump($term);


My question is - how do I retrieve the newly created Term tid?
The var_dump only gives a 


  string(9) "SAVED_NEW"


Why on earth doesn't it return the newly created Entity/Term?!?

I need it in case there will be a child Term later.
I've looked at www.drupal.org/documentation and api.drupal.org. But those pages just confuses me more :-( 

Thank you very much
Why on earth doesn't it return the newly created Entity/Term?!?


Why would it? You already have the term object, why do you need it to be chained in a return from a save method that can and does provide you with extra context??

Just use this:

$term = \Drupal\taxonomy\Entity\Term::create([
  'vid' =&gt; 'subject',
  'langcode' =&gt; 'en',
  'name' =&gt; 'Test af Tag',
  'description' =&gt; [
    'value' =&gt; '&lt;p&gt;My description.&lt;/p&gt;',
    'format' =&gt; 'full_html',
  ],
  'weight' =&gt; -1,
  'parent' =&gt; array(0),
]);

$inserted_or_updated = $term-&gt;save();

$tid = $term-&gt;id();