by Engr. Nayab Bukhari, Syed.
I think problem is here
$einfo = moodle_int_course_enrol($einfo);
if $einfo is defined as above
then here
$einfo = moodle_int_course_enrol($einfo);
it is being redefine and getting function return value.
if $einfo is newly defined then moodle_int_course_enrol($einfo);
will return null because it has null value in parameter.
Best of luck