3v4l.org

run code in 300+ PHP versions simultaneously
<?php use Joomla\CMS\Language\Text; use Joomla\CMS\Date\Date; use Joomla\CMS\Factory; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from('#__content') ->order('id DESC') ->limit('3'); $db->setQuery($query); ?> $cardTemplate = <<<HTML <div class="col-lg-4 col-md-6"> <div class="card"> %1$s <div class="card-body"> <a href="%2$s"> <h5 class="card-title mb-4">%3$s</h5> </a> <time datetime="%4$s" class="mb-2 text-muted">%4$s</time> <p class="card-text">%5$s</p> </div> </div> </div> HTML; $cards = []; foreach ($db->loadObjectList() as $row) { $introImage = json_decode($r->images)->image_intro ?? null; $cardTop = !$introimage || $introimage == '/' ? '<div class="card-img-top holding-image" alt="' . $row->title . '"></div>' : '<img class="card-img-top" src="' . $introImage . '" alt="' . $row->title . '"/>', $cards[] = sprintf( $cardTemplate, $cardTop, // %1$s JRoute::_('index.php?option=com_content&view=article&id=' . $row->id), // %2$s $row->title, // %3$s $row->publish_up, // %4$s mb_strimwidth($row->introtext, 0, 80, "..."), // %5$s } } $pageTemplate = <<<HTML <h2>Heading Here</h2> <div class="row"> %s </div> HTML; printf( $pageTemplate, implode("\n", $cards) );
Output for 8.0.0 - 8.0.8
Fatal error: Uncaught Error: Class "JFactory" not found in /in/1po1G:7 Stack trace: #0 {main} thrown in /in/1po1G on line 7
Process exited with code 255.
Output for 7.3.0 - 7.3.29, 7.4.0 - 7.4.21
Fatal error: Uncaught Error: Class 'JFactory' not found in /in/1po1G:7 Stack trace: #0 {main} thrown in /in/1po1G on line 7
Process exited with code 255.

preferences:
218.34 ms | 460 KiB | 5 Q