3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Допустим есть метод, где мы получаем определенные поля, по типу //... $arProduct['REVIEWS'] = Review::getProductReviews($arProduct['ID']); $arProduct['QUESTIONS'] = Question::getProductQuestions($arProduct['ID']); //... //Нужно сделать так, чтобы клиент мог указать какие поля не нужно загружать из бд. //То есть, если $fieldsToLoad = [REVIEWS, QUESTIONS], значит их не нужно передавать клиенту. Как это возможно сделать? Есть //такой вариант: $fieldsToLoad = [ 'REVIEWS' => function () use ($arProduct, $reviewsSize) { $arProduct['REVIEWS] = Review::getProductReviews($arProduct['ID']); }, 'QUESTIONS' => function () use ($arProduct, $questionsSize) { $arProduct['QUESTIONS'] = Question::getProductQuestions($arProduct['ID']); } ] foreach ($fieldsToLoad as $fieldName => $fieldLoader) { if (!in_array($fieldName, $notLoadFields)) { $fieldLoader(); } } //Но проблема в том, что возможно нужно будет добавить общее условие для каких то полей, как пример: //... if ($block == 60) { $arProduct['REVIEWS'] = Review::getProductReviews($arProduct['ID']); $arProduct['QUESTIONS'] = Question::getProductQuestions($arProduct['ID']); } //... //И тогда получается не очень, так как для каждого элемента массива $fieldsToLoad придется писать отдельное условие. Есть ли //более лучшее решение вопроса?
Output for git.master, git.master_jit, rfc.property-hooks
Parse error: syntax error, unexpected identifier "ID", expecting "]" in /in/hKCiV on line 12
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
140.08 ms | 995 KiB | 7 Q