# Syntax related question \<?php and \<?=

**URL:** <https://forum.getkirby.com/t/syntax-related-question-php-and/4519>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 26, 2016, 6:49pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519 "2016-06-26T18:49:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianlengfelder](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/julianlengfelder/32/7864_2.png) [@julianlengfelder](https://forum.getkirby.com/u/julianlengfelder)\
**Post date:** [June 26, 2016, 6:49pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/1 "2016-06-26T18:49:50Z")

</div>

I feel a bit stupid for asking, but when and why is `<?=` used instead of `<?php`?  
[Kirby-Builder](https://github.com/TimOetting/kirby-builder) makes use of `<?=` for example.

I am just getting started working in php and could not find an answer to this. Would appreciate an explanation or some pointers to relevant literature.

Cheers & thanks  
Julian

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 26, 2016, 6:52pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/2 "2016-06-26T18:52:34Z")

</div>

`<?= ?>` is the same as `<?php echo ?>`, only shorter. It is generally good practice to use the short code for echoing something (but you can use both).

Don’t use the short code `<? ... ?>` without the `=` for general php purposes (i.e. when not echoing something), though.

Example:

```auto
<?= $page->title() ?>

```

is the same as:

```auto
<?php echo $page->title() ?>

```

**Don’t** do this, however:

```auto
<? 
  foreach($pages as $p) {
   ....
  }
?>

```

Always use the php tag:

```auto
<?php
  foreach($pages as $p) {
    ...
  }
?>

```

---

<div class="post-metadata">

**Author:** ![julianlengfelder](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/julianlengfelder/32/7864_2.png) [@julianlengfelder](https://forum.getkirby.com/u/julianlengfelder)\
**Post date:** [June 26, 2016, 6:55pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/3 "2016-06-26T18:55:58Z")

</div>

Ah nice. Thanks for the short explanation.

Are there other shorthands for things like `<?php foreach` for example?

EDIT: Thanks for the further clarification with the examples.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 26, 2016, 6:59pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/4 "2016-06-26T18:59:13Z")

</div>

No, there is no shorthand for `foreach`, see my edited post above.

---

<div class="post-metadata">

**Author:** ![1n3JgKl9pQ6cUMrW](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/1n3jgkl9pq6cumrw/32/2368_2.png) [@1n3JgKl9pQ6cUMrW](https://forum.getkirby.com/u/1n3JgKl9pQ6cUMrW)\
**Post date:** [June 26, 2016, 7:06pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/5 "2016-06-26T19:06:08Z")

</div>

**[http://php.net/manual/en/ini.core.php#ini.short-open-tag](http://php.net/manual/en/ini.core.php#ini.short-open-tag)**

Maybe this is interesting for you.

Not all developers / server-admins like the _Short Open Tag_ (for various reasons), so I never use it (been there, done that… too much trouble with it).

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [June 26, 2016, 7:07pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/6 "2016-06-26T19:07:54Z")

</div>

Just a little image that’s good to keep in mind:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/9/9fd316286db0fbc7005c28c4231ca57323837bc2.png)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 26, 2016, 7:12pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/7 "2016-06-26T19:12:20Z")

</div>

The short open tag `<? ?>` is different from `<?= ?>` as I explained above and **should not be used**.

Kirby requires PHP 5.4+, so the **short echo tag** may safely be used. PHP 5.4 has reached its end of life, anyway: [http://php.net/supported-versions.php](http://php.net/supported-versions.php)

You should be using PHP 5.6+ these days.

See this discussion as well: [To PHP Short Tag or not to PHP Short Tag?](https://forum.getkirby.com/t/to-php-short-tag-or-not-to-php-short-tag/2698)

---

<div class="post-metadata">

**Author:** ![1n3JgKl9pQ6cUMrW](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/1n3jgkl9pq6cumrw/32/2368_2.png) [@1n3JgKl9pQ6cUMrW](https://forum.getkirby.com/u/1n3JgKl9pQ6cUMrW)\
**Post date:** [June 26, 2016, 7:33pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/8 "2016-06-26T19:33:07Z")

</div>

Cool - thx! 👍

I know, but not all of my clients can migrate to PHP 5.6+ (for several reasons).

In the ideal world, everyone is using the most recent versions of PHP (or, to be honest - no PHP at all) - but I guess we’re not living in the ideal world 🙂

I even have clients, that use PHP 5.2… can you imagine… :’(

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 26, 2016, 7:50pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/9 "2016-06-26T19:50:55Z")

</div>

Well, that may be so. But as I said, the current version of Kirby requires PHP 5.4+, so you have no other choice.

Even a cheap shared hosting plan let’s you choose your PHP version a a per-domain basis. I think that money is well invested in security.

I understand that clients might have old PHP versions running for old applications but that should not stop you from using current PHP version for current software.

---

<div class="post-metadata">

**Author:** ![1n3JgKl9pQ6cUMrW](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/1n3jgkl9pq6cumrw/32/2368_2.png) [@1n3JgKl9pQ6cUMrW](https://forum.getkirby.com/u/1n3JgKl9pQ6cUMrW)\
**Post date:** [June 26, 2016, 8:07pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/10 "2016-06-26T20:07:04Z")

</div>

I 100% agree with you - but I have a couple of clients in South-America, and the IT-level over there is not what we can except in Europe.

The highest bandwidth is about 2G (or they use TDMA which does not allow mobile internet at all), they sell server-space for maximum of 25mb… etc… (and they pay a lot for this).

I even have one client on a server that’s not updated since 1998 - can you imagine?

Off course they don’t use Kirby, I use Wordpress for those instances 🙂

So, it’s a lot off-topic - but thanks again for your outstanding knowledge and support!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/syntax-related-question-php-and/4519/11 "2025-02-06T16:57:42Z")

</div>

Archived on February 6, 2025, 4:57pm UTC


