file_put_contents

Supported Versions: PHP 5, PHP 7, PHP 8
Write data to a file
<?php file_put_contents(    string $filename,    mixed $data,    int $flags = 0,    ?resource $context = null): int|false
<?php             return false;

        }



        return (bool) file_put_contents($filePath, json_encode([

            ...match (true) {

                class_exists('\Illuminate\Support\Str') => [

                    'preset' => 'laravel',

                ],

                default => [

                    'preset' => 'base',

                ],

            },

            'ignore' => [

                'words' => [

                    'php',

                ],

                'paths' => [],

            ],

        ], JSON_PRETTY_PRINT));

    }
<?php     {

        $filePath = ProjectPath::get().'/'.self::JSON_CONFIGURATION_NAME;



        file_put_contents($filePath, json_encode([

            ...$this->preset !== null ? ['preset' => $this->preset] : [],

            'ignore' => [

                'words' => $this->whitelistedWords,

                'paths' => $this->whitelistedPaths,

            ],

        ], JSON_PRETTY_PRINT));

    }

}
<?php     {

        $key = $this->getCacheKey($key);



        file_put_contents($this->getCacheFile($key), serialize($value));

    }
<?php     $cache->set($key, 'test');



    file_put_contents($cache->getCacheFile($cache->getCacheKey($key)), 'invalid serialized string');



    expect($cache->get($key))->toBeNull();

});
<?php     $cache->set($key, 'test');



    file_put_contents($cache->getCacheFile($cache->getCacheKey($key)), false);



    expect($cache->get($key))->toBeNull();

});