Laravel 5: Setting Data on Objects Without Overwriting Existing Data With data_fill

April 15, 2018 —John Koster

The data_fill helper function accomplishes the same fundamental task as the data_set helper function. The only difference is that the data_fill does not define an optional $overwrite parameter. data_fill internally makes a call to the data_set helper function with $overwrite set to false. This function does not overwrite data.

#Signature

The signature of the data_fill function is:

1function data_fill(
2 &$target,
3 $key,
4 $value
5);

#Example Use

The following function calls are equivalent and would produce the same results:

1// Create a object to work with.
2$testObject = new stdClass;
3 
4// Set data using `data_fill`.
5data_fill($testObject, 'name', 'Jane');
6 
7// Set data using `data_set`.
8data_set($testObject, 'name', 'Jane', false);

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.