laravel - PHP 5.3.2 alternative to using $this inside an anonymous function? -


i using laravel 4 , php build new application. works fine on dev server running php 5.4.x boss insist has run version 5.3.2

i have spent whole day fixing work 5.3.2 , have everything, thought, until ran issue code below.

my problems start @ line...
db::transaction(function($clock_in_webcam_image) use ($clock_in_webcam_image)

i believe type of code might not work version of php? if case, options run same code or have doing same action?

would appreciate this. unfortunate boss told me straight out no not allow update newer php stuck in hard spot right now

// create new time card record when user clocks in public function createtimecard($clock_in_webcam_image) {     // create both timecard , timecard record tables in transaction     db::transaction(         function ($clock_in_webcam_image) use ($clock_in_webcam_image) {             $timecard = db::table('timeclock_timecard')->insertgetid(                 array(                     'user_id'               => $this->user->user_id,                     'clock_in_datetime'     => $this->datetime->format($this->dateformat),                     'clock_in_timestamp'    => $this->datetime->gettimestamp(),                     'clock_in_webcam_image' => $clock_in_webcam_image                 )             );              $timecardpunchentry = db::table('timeclock_punch_entry')                 ->insertgetid(                     array(                         'timecard_id'          => $timecard,                         'user_id'              => $this->user->user_id,                         'created_at_datetime'  => $this->datetime->format($this->dateformat),                         'created_at_timestamp' => $this->datetime->gettimestamp(),                         'clock_type'           => 'clock_in',                         'webcam_image'         => $clock_in_webcam_image                     )                 );              return $timecard;         }     ); } 

update

in response bansi's comment...is mean do...

db::transaction(function() use($mymodel){     $mymodel->updatetable1();     $mymodel->updatetable2(); }) 

before php 5.4.0, not use $this inside anonymous function. there simple workaround though can use use construct pass variables functions scope. also, using use construct incorrectly $clock_in_webcam_image not defined in parent scope.

$user = $this->user; $datetime = $this->datetime;  db::transaction(function($clock_in_webcam_image) use ($user, $datetime) {     // snip      array(         'user_id' => $user->user_id,         'clock_in_datetime' => $datetime->format($this->dateformat),         'clock_in_timestamp' => $datetime->gettimestamp(),         'clock_in_webcam_image' => $clock_in_webcam_image     )      // snip }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -