Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:44:49+00:00 2026-05-31T08:44:49+00:00

Recently I found out about with and let statements for javascript. I’m interested in

  • 0

Recently I found out about with and let statements for javascript.

I’m interested in achieving something like mentioned here: https://stackoverflow.com/a/1462102/393406, except for PHP in OOP fashion.

Like:

$builder = new markupbuilder();
with($markupbuilder){
    div(
        h1('A title...') . 
        p('This is ' . span('paragraph') . ' here.')
    );
}

// respectively
$builder->div(
    $builder->h1('A title...') . 
    $builder->p('This is' . $builder->span('paragraph') . ' here')
);

So, is there something similar for PHP or how could I achieve this in PHP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:44:51+00:00Added an answer on May 31, 2026 at 8:44 am

    This is sort of a trite reply, but you have not saved a single character of typing in your example, and I believe that’s the whole point of using with. The with statement also introduces ambiguity. Do you want to call getElementsByTagName on the DOMDocument object, or do you want to call the globally defined function of the same name?

    As for let, PHP variables apply to the scope they are in by default — you have to use the global keyword not only to make them globally accessible in general but any time you want to use them in another scope (and I would suggest never to use them period). Some may say it is a limitation on PHP that if and other constructs don’t have their own scope, and let may be useful there, but if you wanted another variable in one of those constructs you could just declare it separately or move the functionality to a function scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently found out about livecoding where someone will program something on the fly
I recently found out about auto-properties and like them quite a lot. At this
I recently found out about C# extension methods and wrote this one: /// <summary>
I recently found out about n-grams and the cool possibility to compare frequency of
Recently I have been learning about WMI and WQL. I found out the list
I recently found out about the awesomeness of the iTunes COM for Windows SDK.
I recently found out about Presenter First and read their whitepapers and blogs, etc.
I recently found out about oEmbed which is a fomat for allowing an embedded
I've recently found out about protocol buffers and was wondering if they could be
I only recently found out about URL rewriting , so I've still got a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.