Fatal error: Call to a member function get_page_permastruct() on a non-object

The WordPress environment is not yet fully initialized when your plugin files are loaded, it’s almost always too early to safely run code that interacts with core at that point.

WordPress achieves its initial state through a process which contains its own set of actions and filters, so plugins load before that happens to allow them to hook into that process.

The action and filter system is the basis of core / plugin interaction, just about everything a plugin does will be tied to an action or filter. It’s a simple system that provides a roadmap of the whole request process, allowing you to manage the order of when your plugin code executes.