3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php while (($peopleData = fgetcsv($handle, 1000, ",")) !== FALSE) { // echo count($peopleData) . ' - '. $fieldsCount; exit; if (count($peopleData) == $fieldsCount) { $attributes = array_combine(array_merge($this->fileUploadFields, $customColumns), $peopleData); $attributes = $this->formatAttributes($attributes); $model = null; if (null != $attributes['firstName'] && null != $attributes['lastName'] && null != $attributes['dateOfBirth']) { $model = User::model()->findByAttributes(array('firstName' => $attributes['firstName'], 'lastName' => $attributes['lastName'], 'dateOfBirth' => $attributes['dateOfBirth']), 'userType NOT IN ("' . User::POLITICIAN . '")'); } if (null == $model && null != $attributes['email']) { $model = User::model()->findByAttributes(array('email' => $attributes['email']), 'userType NOT IN ("' . User::POLITICIAN . '")'); } // Check Email contact limit if (!empty($attributes['email']) && $tc->packageInfo['totalEmailContacts'] < $emailContactsCount) { $this->isEmailContactLimitExceed = true; break; } if ($model == null) { $model = new User; $model->joinedDate = date('Y-m-d H:i:s'); $model->userType = User::SUPPORTER; $customFields = CustomValue::model()->getCustomData(CustomType::CF_PEOPLE, 0, CustomField::ACTION_CREATE, $attributes, CustomType::CF_SUB_PEOPLE_BULK_INSERT); } else { if ($model->userType != User::NON_SUPPORTER) { $model->userType = User::SUPPORTER; } $customFields = CustomValue::model()->getCustomData(CustomType::CF_PEOPLE, $model->id, CustomField::ACTION_CREATE, $attributes, CustomType::CF_SUB_PEOPLE_BULK_INSERT); } $model->scenario = 'bulkPeople'; $model->attributes = $attributes; $model->countryCode = $this->countryCode; $model->isManual = 1; $oldKeywords = $model->keywords; $model->keywords = empty($this->keywords) ? $oldKeywords : $this->keywords; $model->delStatus = User::NOTDELETE; $model->supporterDate = date('Y-m-d H:i:s'); $customErrors = array(); foreach ($attributes as $key => $val) { foreach ($customFields as $k => $customField) { if ($key == $customField->fieldName) { $customField->fieldValue = $val; $customValues[$customField->fieldName] = $val; $customField->validate(); $customErrors[] = $customField->errors; } } } $attributes = array_merge($model->attributes, $customValues); try { $valid = $model->validate(); $valid = CustomField::validateCustomFieldList($customFields) && $valid; if ($valid && $model->saveWithCustomData($customFields, null, false)) { $this->bulkSuccessCount++; if (!empty($model->email)) { $emailContactsCount++; } Yii::app()->appLog->writeLog("People created. People data:" . @json_encode($attributes)); $fbModule = FbProfile::model()->findByAttributes(array('userId' => $model->id)); if ($fbModule != null) { Feed::model()->updateFeedUserType($fbModule->fbUserId, $model->userType); } $twModule = TwProfile::model()->findByAttributes(array('userId' => $model->id)); if ($twModule != null) { Feed::model()->updateFeedUserType($twModule->twUserId, $model->userType); } } else { $errorKey = array_keys($model->errors); if (empty($model->errors)) { $errorKey = array_keys(current(array_filter($customErrors))); $firstElement = current(array_filter($customErrors)); $errorMsg = $firstElement[$errorKey[0]][0]; } else { $errorMsg = $model->errors[$errorKey[0]][0]; } Yii::app()->appLog->writeLog("People create failed. People data:" . @json_encode($attributes)); $this->fileErrors[] = Yii::t('messages', 'Failed,') . $errorMsg . "," . implode(",", $peopleData); } } catch (Exception $e) { Yii::app()->appLog->writeLog("People create failed. Error:{$e->getMessage()}"); } } else { Yii::app()->appLog->writeLog("People create failed. Data line:" . @json_encode($peopleData)); $this->fileErrors[] = Yii::t('messages', 'Failed, Number of data fields not match.') . "," . implode(",", $peopleData); } } fclose($handle);
Output for 7.2.0
Notice: Undefined variable: handle in /in/QZeg2 on line 3 Warning: fgetcsv() expects parameter 1 to be resource, null given in /in/QZeg2 on line 3 Warning: count(): Parameter must be an array or an object that implements Countable in /in/QZeg2 on line 5 Notice: Undefined variable: fieldsCount in /in/QZeg2 on line 5 Fatal error: Uncaught Error: Using $this when not in object context in /in/QZeg2:7 Stack trace: #0 {main} thrown in /in/QZeg2 on line 7
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Notice: Undefined variable: handle in /in/QZeg2 on line 3 Warning: fgetcsv() expects parameter 1 to be resource, null given in /in/QZeg2 on line 3 Notice: Undefined variable: fieldsCount in /in/QZeg2 on line 5 Fatal error: Uncaught Error: Using $this when not in object context in /in/QZeg2:7 Stack trace: #0 {main} thrown in /in/QZeg2 on line 7
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Notice: Undefined variable: handle in /in/QZeg2 on line 3 Warning: fgetcsv() expects parameter 1 to be resource, null given in /in/QZeg2 on line 3 Notice: Undefined variable: fieldsCount in /in/QZeg2 on line 5 Fatal error: Using $this when not in object context in /in/QZeg2 on line 7
Process exited with code 255.