Jump to content

ProcessWire should support PHP 8.1+ only, and here's why...


MrSnoozles
 Share

Recommended Posts

Clickbait title aside, I recently found a cool new feature in PHP 8.1 and wanted to share it with you, in case you didn't know this either.

Starting with PHP 8.1 you can write $this->method(...) [yes, that's the actual syntax, not a placeholder] to reference a method. I find this super convenient, especially for defining hooks. Plus the IDE can refactor this much better than the traditional [$this, 'method'] callback.

 

<?php

class MyModule {
	public function init() {
    	$this->addHookAfter('ProcessPageView::finished', $this->doSomething(...));
    }
  
    private function doSomething(HookEvent $event) {
    	// TODO: something
    }
}

 

 

Edited by MrSnoozles
  • Like 8
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...