Table Schema in specific field column

I was read tutorial in

next I wass added a few line in UsersTable.php below

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\Event\Event;
use ArrayObject;
use Cake\Utility\Security;
use Cake\Database\Schema\Table as Schema;
use Cake\Database\Type\BaseType;
use Cake\Table\boolean;
use Cake\Database\Schema\TableSchemaInterface;
use Cake\Database\Type\ColumnSchemaAwareInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\Datasource\EntityInterface;
use Cake\Collection\CollectionInterface;

//protected function untuk encrypt dan decrypt
	protected function _initializeSchema(Schema $table)
		$table->setColumnType('whatsapp', 'crypted');
		return $table;
	//before save to encrypt and output formatters
	public $encryptedFields = ['whatsapp'];
	public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
		foreach($this->encryptedFields as $fieldName) {
			if($entity->has($fieldName)) {
					Security::encrypt($entity->get($fieldName), Security::getSalt())
		return true;
	public function beforeFind(Event $event, Query $query, ArrayObject $options, boolean $primary)
			function($results) {
				return $results->map(function ($row) {
					foreach($this->encryptedFields as $fieldName) {
						if(isset($row[$fieldName])) {
							$row[$fieldName] = Security::decrypt($row[$fieldName], Security::getSalt());
					return $row;

when I test run, the error message display below

Fatal error: Declaration of App\Model\Table\UsersTable::_initializeSchema(Cake\Database\Schema\Table $table) must be compatible with Cake\ORM\Table::_initializeSchema(Cake\Database\Schema\TableSchemaInterface $schema): Cake\Database\Schema\TableSchemaInterface in C:\xampp\htdocs\baksoganteng\src\Model\Table\UsersTable.php on line 115

where’s the part to be fix that trouble, thanx for everyone want to help me


protected function _initializeSchema(Schema $table)


protected function _initializeSchema(TableSchemaInterface $table): TableSchemaInterface

and make sure you have

use Cake\Database\Schema\TableSchemaInterface;

at the top of your class.

This answer in stackoverflow is quite old (2015) so there have been quite some changes in the CakePHP framework.

But your error just comes up, because an overwritten function (your _initializeSchema) needs to have the same

  • arguments with the same argument types
  • return type

as the parent function it overwrites.

thanx @KevinPfeifer for the answer