Skip to content

(PoC) UI PHP components: Add Card component - #84909

Draft
juanfra wants to merge 5 commits into
try/84036-ui-components-php-build-markupfrom
try/84036-ui-components-php-card
Draft

juanfra wants to merge 5 commits into
try/84036-ui-components-php-build-markupfrom
try/84036-ui-components-php-card

Conversation

@juanfra

@juanfra juanfra commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Update: rebuilt on top of #85759. Based on the feedback below, trusted() is gone, so the safe object only comes from a component's output or from sanitized(), and it can't be unserialized. __toString() stays for now: the context-aware templating in wordpress-develop#5949 would be a better foundation for this, so I see the safe object as a stand-in for it.

What?

Builds on #85759 #84905.

Adds Card to try composition, and to make HTML content safe by default, as discussed in #84036

How?

Content gets its own argument now,gutenberg_get_ui_component( 'card', $props, $content ). The idea is that it's escaped unless we know it's safe:

  • If you pass a string, it's escaped like any prop.
  • If you pass another component, it goes in as HTML. Components now return a Gutenberg_UI_Safe_HTML object, which you can still echo as usual.
  • If you pass a closure, whatever it prints goes in, like in any template, so it's on the closure to escape its own values.
  • For any other HTML, you have to mark it yourself with Gutenberg_UI_Safe_HTML::sanitized() (runs wp_kses_post()) or trusted().

To check composition, the build renders a Card with a Button inside using React, and a test makes sure PHP puts them together the same way. I also removed the unused "format": "html" path, which printed HTML as is.

There are a few things I'd love thoughts on:

  1. Closures are only as safe as what they print. They're handy for richer content, but whatever they echo goes in as is, so the caller still has to escape their own values.
  • trusted() skips escaping on purpose, for HTML that didn't come from a component (like the output of a WP function). It's explicit and easy to find in review, but nothing stops someone from misusing it. Update: Removed trusted().
  • Components now return an object instead of a string. That's what lets them tell their own output apart from a plain string, but it's a bit unusual for a get_ function in WordPress. It still works with echo, so most code shouldn't notice.

Testing Instructions

  1. Run npm run build.
  2. Go to Tools > UI Components and check the Composition section: a Card with some text and a Button.
  3. Run npm run test:unit:php:base -- --filter Gutenberg_UI_Components_Test.

Use of AI Tools

I used Claude Code to help prototype and write parts of this code. I reviewed and tested all of it.

@juanfra
juanfra added this pull request to stack #84910 October 16, 2026 09:41
@juanfra juanfra added [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible [Package] UI /packages/ui labels Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

📦 Bundle size

Size Change: 0 B

Total Size: 8.58 MB

b5eda5d Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
timeToFirstByte 41.75 ms +3.71% -2.63% 45.35 ms +12.9% -4.3% -7.94%
largestContentfulPaint 72 ms +5.56% -5.56% 80 ms +5% -7.5% -10%
lcpMinusTtfb 28.7 ms +21.08% -7.32% 30.6 ms +13.89% -6.54% -6.21%
wpBeforeTemplate 21.82 ms +3.39% -2.15% 23.02 ms +14.07% -1.82% -5.21%
wpTemplate 16.57 ms +5.01% -3.68% 18.43 ms +5.59% -5.7% -10.09%
wpTotal 38.49 ms +3.79% -2.7% 41.85 ms +13.02% -4.16% -8.03%
wpMemoryUsage 7.70 MB +0% -0% 7.70 MB +0% -0% 0%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
timeToFirstByte 36.6 ms +6.01% -6.42% 36.4 ms +8.65% -4.4% 0.55%
largestContentfulPaint 80 ms +0% -5% 80 ms +5% -0% 0%
lcpMinusTtfb 42.4 ms +2.36% -1.53% 44.15 ms +2.49% -2.04% -3.96%
wpBeforeTemplate 19.56 ms +13.34% -3.94% 19.8 ms +8.23% -3.43% -1.21%
wpTemplate 13.53 ms +4.29% -6.73% 13.77 ms +3.12% -5.81% -1.74%
wpTotal 33.75 ms +6.22% -6.1% 33.51 ms +8.15% -4.18% 0.72%
wpMemoryUsage 6.39 MB +0% -0% 6.39 MB +0% -0% 0%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
mediaProcessingJpeg 325.46 ms +1.09% -0.98% 328.17 ms +0.36% -0.7% -0.83%
mediaProcessingAvif 4845.21 ms +0.1% -0.22% 4870.12 ms +0.13% -0.33% -0.51%
mediaProcessingJpegToAvif 3382.74 ms +0.03% -0.18% 3406.07 ms +0.07% -0.33% -0.68%

media-upload

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
jpegUploadProcessing 1440.12 ms +1.34% -0.82% 1447.19 ms +0.79% -1.01% -0.49%
pngUploadProcessing 220.41 ms +5.02% -13.29% 226.6 ms +1.39% -2.11% -2.73%
largeJpegUploadProcessing 1424.7 ms +0.39% -0.4% 1420.27 ms +0.37% -0.83% 0.31%
multipleImageUploadProcessing 1509.49 ms +1.25% -0.37% 1504.73 ms +0.42% -1.92% 0.32%

post-editor

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
serverResponse 318.34 ms +4.94% -8.12% 322.46 ms +2.23% -9.92% -1.28%
firstPaint 286.67 ms +37.15% -19.02% 286.03 ms +34.13% -5.65% 0.22%
domContentLoaded 680.24 ms +4.02% -2.9% 663.13 ms +3.48% -1.5% 2.58%
loaded 681.02 ms +4.04% -2.89% 663.85 ms +3.48% -1.51% 2.59%
firstContentfulPaint 399.21 ms +7.61% -3.68% 388.82 ms +4.99% -2% 2.67%
firstBlock 1723.22 ms +2.27% -1.79% 1701.12 ms +1.07% -0.2% 1.3%
type 16.41 ms +2.86% -10.05% 15.09 ms +6.36% -7.29% 8.75%
typeWithoutInspector 15.39 ms +3.96% -5% 14.67 ms +5.18% -4.09% 4.91%
typeWithTopToolbar 19.98 ms +2% -8.66% 19.13 ms +5.59% -4.03% 4.44%
typeContainer 7.05 ms +3.83% -6.38% 6.84 ms +24.12% -8.19% 3.07%
focus 97.33 ms +3.26% -5.24% 95.4 ms +5.3% -3.14% 2.02%
firstFocus 200.77 ms +0% -0% 199.57 ms +0% -0% 0.6%
selectAll 319.46 ms +3.35% -1.76% 315.45 ms +1.11% -1.82% 1.27%
undo 26.51 ms +5.36% -6.53% 24.53 ms +4.57% -4.69% 8.07%
listViewOpen 67.52 ms +11.79% -10.1% 60.76 ms +1.46% -5% 11.13%
inserterOpen 35.01 ms +3.8% -5.74% 32.21 ms +4.19% -5.12% 8.69%
inserterHover 9.6 ms +6.88% -4.06% 9.44 ms +5.72% -6.36% 1.69%
inserterSearch 7.19 ms +3.89% -6.12% 7.26 ms +4.41% -5.65% -0.96%
loadPatterns 495.07 ms +2.12% -2.28% 498.4 ms +4.9% -5.27% -0.67%
wpTotal 309.69 ms +4.73% -8.36% 313.84 ms +2.26% -10.22% -1.32%
wpMemoryUsage 14.75 MB +0% -0% 14.75 MB +0% -0% 0%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 8cae760 try/84036-ui-components-php-build-markup % Change
serverResponse 404.97 ms +0.73% -0.75% 405.7 ms +0.84% -8.56% -0.18%
firstPaint 406.01 ms +22.58% -19.85% 381.04 ms +2.93% -14.72% 6.55%
domContentLoaded 867.91 ms +2.32% -1.26% 869.03 ms +2.8% -1.96% -0.13%
loaded 868.91 ms +2.32% -1.27% 869.91 ms +2.83% -1.96% -0.11%
firstContentfulPaint 499.63 ms +6.4% -1.65% 493.59 ms +3.58% -2.7% 1.22%
firstBlock 2422.24 ms +3.17% -1.22% 2412.93 ms +1.48% -1.45% 0.39%
type 20.14 ms +0.65% -14.75% 18.47 ms +7.69% -6.12% 9.04%
navigate 122.58 ms +3.25% -2.66% 119.6 ms +6.83% -2.23% 2.49%
loadPatterns 1222.92 ms +6.06% -3.24% 1139.78 ms +11.19% -6.99% 7.29%
loadPages 974.57 ms +1.29% -2.3% 975.47 ms +2.25% -2.19% -0.09%
wpTotal 395.41 ms +0.75% -0.75% 395.95 ms +0.89% -8.75% -0.14%
wpMemoryUsage 12.77 MB +0% -0% 12.77 MB +0% -0% 0%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

b5eda5d Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Undo restores the post selection when another synced entity is loaded in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
moves selected text within a paragraph in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "second First third",
+       "content": "First second third",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:1209:41
should not have a dead zone above an aligned block in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
TypeError: Cannot read properties of null (reading 'y')
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1053:39

b5eda5d Run

@aduth

aduth commented Oct 22, 2026

Copy link
Copy Markdown
Member

This is really interesting @juanfra ! While it's still a draft, there's a lot of really interesting ideas here, particularly around supporting composition and having safer defaults for component content.

Since this came up in the context of #84036 (comment) and around Core#60229, I wonder if @dmsnell would have any thoughts on this approach. I expect there could be value in generalizing this behavior beyond just components themselves as explored in the related ticket, and this could serve as a valuable use-case, proof-of-concept, and maybe even something we could merge and build expand from. In particular, it feels to me like a good middle-ground to adopt something like Rails' SafeBuffers and treating string markup as untrusted by default except for what we know to be produced by the implementation of the components themselves.

One interesting question that comes up for me in looking at the Card example is contrasting with the @wordpress/ui implementation, and notably the choice between a flattened API and compound components we use in the React library. I feel like the flattened structure may ultimately make more sense in the context of PHP components, but I wonder if you have any thoughts on how we'd think about mapping between subcomponents and the PHP component options.

I also like how you approached different content options like those mentioned in #84036 (comment) by not just choosing one, but supporting consumers to mix-and-match based on their individual need, where one option may work better for specific situations. Depending on risk tolerance (and in particular question about "closures are only as safe as what they print", we could ultimately choose to drop some options if we'd rather funnel people toward one. Or we could add it later if we don't want to bind ourselves to that decision now.

To your specific questions of feedback:

Closures are only as safe as what they print. They're handy for richer content, but whatever they echo goes in as is, so the caller still has to escape their own values.

I see the risk. Personally it feels reasonable, insofar that breaking out of PHP delimiters assumes and understanding that you'd be working more directly with raw HTML and expected to use appropriate escaping functions when working in that context. Given my own understanding of the types of security issues we'd be trying to protect against, many of them often come in the form of concatenating strings that are assumed to be plaintext but can be manipulated maliciously to include markup. In the closure example context, I think there'd be an understanding of content in that output to be HTML. That being said, it's of course objectively "safer" to just not allow it at all as an option, and to me this feels like a question between reasonable security and developer ergonomics and flexibility.

trusted() skips escaping on purpose, for HTML that didn't come from a component (like the output of a WP function). It's explicit and easy to find in review, but nothing stops someone from misusing it.

I agree. I think the name itself can do a lot to communicate its intent. In that regard, it doesn't trouble me very much as-is. If we were especially concerned we could name it something that communicates its intent more clearly (akin to React's dangerouslySetInnerHTML), or expect this to be something that would be protected at call-sites via tools like linters (akin to how rules exist for Rails' html_safe usage).

Components now return an object instead of a string. That's what lets them tell their own output apart from a plain string, but it's a bit unusual for a get_ function in WordPress. It still works with echo, so most code shouldn't notice.

I was curious about precedent for this kind of "duck typing" in WordPress, and there's a few examples (e.g. WP_Theme, WP_HTML_Tag_Processor), but true to call out that this is relatively unconventional. This is more common in other languages like the Ruby inspiration I've been drawing from, and in the process of digging into this I also discovered that this design and purpose is almost identical to Laravel's HtmlString class. Overall though, this too doesn't feel particularly concerning to me.

@dmsnell

dmsnell commented Oct 22, 2026

Copy link
Copy Markdown
Member

thanks @aduth for the callout here. unfortunately I do not have the cycles available to give this the attention it deserves, but I like the general idea.

a couple of my explorations are linked in the Core-60229, which you linked to. there are a few things I’ve been hunting, which I think are important in a system like this:

  • there should be no way to instantiate a trusted class without running through the sanitizer. I think this means it will have to be an anonymous class. React creates well-formed HTML, but it does not apply WordPress policies which ensure safe HTML.
  • it might be important to defer rendering until “the end” because permissions may change as the content moves through the system.
  • we should make sure we cannot unserialize a user-submitted value into the trusted class, which could lead to a chain up to RCE

the duck-typing note is important. a general __toString() method itself is dangerous because it would bleed out the safety provided by the class wrapper, if it’s meant to hold content until render. worse though, Core is filled with checks like is_string() which have a tendency to cause breakage when code really needs to know if a given object is string-like.

I want this to happen and I want it supported everywhere in Core. as long as the work is slow I think we can make that happen.

if wanting to experiment more, I think it’s likely more valuable to be trying to make something specific and internal and scary-sounding to others so that we don’t over-rapidly adopt something that isn’t clearly vetted and generalizable.

@juanfra

juanfra commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Thanks so much for looking into this! Appreciate it :)

I wonder if you have any thoughts on how we'd think about mapping between subcomponents and the PHP component options.

@aduth I agree that flat makes more sense for PHP. I believe the way to map them is by what each subcomponent does. For example:

  • Structural wrappers are built by PHP (Card.Root, Card.Header)
  • Parts with text or content become props or the content (Card.Title, Card.Content)
  • Optional parts become named slots (header actions, a footer)
  • Repeated parts become a list of items (tabs, menu items)

That's more or less the idea of how it works in this PR, with the mapping in the component.json. Slots and lists of items would follow the same approach. I'd avoid exposing subcomponents since the components CSS depends on its structure.

Depending on risk tolerance [...] we could ultimately choose to drop some options if we'd rather funnel people toward one.

@aduth Agreed. I believe it'd be easier to drop an option later than adding it back.

this design and purpose is almost identical to Laravel's HtmlString class

Thanks for digging into the precedents! That's a good reference, and it looks very close, yes.

a general __toString() method itself is dangerous because it would bleed out the safety provided by the class wrapper

@dmsnell Thanks! That makes sense, and I hadn't considered all the is_string() checks in core. An alternative could be the component function returning a plain string and passing nested components as specs (name and props) instead of rendered objects. Then the parent renders everything at the end, which should also take care of deferring the rendering.

there should be no way to instantiate a trusted class without running through the sanitizer.

Good point 👍

I think it’s likely more valuable to be trying to make something specific and internal and scary-sounding

That makes sense as well

@dmsnell

dmsnell commented Oct 23, 2026

Copy link
Copy Markdown
Member

returning a plain string and passing nested components as specs (name and props) instead of rendered objects

These are effectively what the Shortblocks/Bits proposal is creating, and forms the basis for my HTML templating’s context-aware auto-escaping, but in tokens that are part of HTML instead of layering a custom syntax on top of or underneath HTML.

The idea for how these fit together is that the template merely defines slots into which to render content. If the values associated with those slots are strings, it should be escaped to preserve the rendering of that text verbatim. However, if the value is one of the wrapped markup containers, it will be safely combined with tags and all.

<!-- profile.html -->
<div class="profile" data-user-id="</%id>" data-name="</%name>">
	<a href="</%url>"></%name></a>
</div>
WP_HTML::render(
	file_get_contents( __DIR__ . '/profile.html' ),
	array(
		'id'   => 14,
		'name' => WP_HTML::template( '<name>Dennis&nbsp;Snell</name>' ),
		'url'  => 'https://profiles.wordpress.org/dmsnell',
	)
);

So the thing here is that we don’t have to send distinct values for the placeholders for each distinct context in which they render, nor do we have to escape any values (and shouldn’t!). When the template renders the data-name field, because it receives the wrapped markup container, and because it knows attribute values may only contain text, it will remove the <name> tags and interpret the &nbsp;; for the contents of the <a> tag, however, it will preserve the <name> tags.

<div class="profile" data-user-id="14" data-name="Dennis Snell">
	<a href="https://profiles.wordpress.org/dmsnell"><name>Dennis Snell</name></a>
</div>

Or the classic example I like to use, URLs which have for display and for data modes.

<a href="</%url>"></%url></a>

Passed https://xn-google.com

<a href="https://xn-google.com">https://䕮䕵䕶䕱.com</a>

Most of this work could be done, but due to various shufflings of priorities and needs it has been deferred, as also some nuanced design choices that still remain.

@juanfra

juanfra commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Thanks for the links and examples @dmsnell, super helpful!

It's good to see the idea already has a home. The context-aware escaping is close to what I tried, but having the template take care of that sounds like a much better foundation. It'd be a great fit for these components moving forward.

A component can describe its React output as a render tree, like Card.Root with Card.Header and Card.Content, and its fixtures can include other components as content. Each component.json also gets an example, used by the fixtures and the preview.
Card's content can be text, another component as array( 'component' => …, 'props' => …, 'content' => … ), or a list of both. PHP renders nested components itself and escapes all text, so the HTML only comes from components and escaped text. Parity tests check Card with a Button inside against React.
@juanfra
juanfra force-pushed the try/84036-ui-components-php-card branch from 8777572 to da683c5 Compare October 28, 2026 09:51
@github-actions github-actions Bot added [Package] Element /packages/element [Package] Date /packages/date [Package] Data /packages/data [Package] Server Side Render /packages/server-side-render [Package] A11y /packages/a11y [Package] Autop /packages/autop [Tool] Babel preset /packages/babel-preset-default [Tool] Browserslist config /packages/browserslist-config [Package] DOM ready /packages/dom-ready [Package] Hooks /packages/hooks [Package] i18n /packages/i18n [Package] is-shallow-equal /packages/is-shallow-equal [Tool] npm-package-json-lint config /packages/npm-package-json-lint-config [Tool] WP Scripts /packages/scripts [Package] Url /packages/url labels Oct 28, 2026
@github-actions github-actions Bot added [Tool] E2E Test Utils /packages/e2e-test-utils-playwright [Package] Edit Post /packages/edit-post [Package] Data Controls /packages/data-controls [Package] Priority Queue /packages/priority-queue [Package] Edit Widgets /packages/edit-widgets [Tool] Dependency Extraction Webpack Plugin /packages/dependency-extraction-webpack-plugin [Tool] Env /packages/env [Package] E2E Tests /packages/e2e-tests [Tool] Create Block /packages/create-block [Tool] Prettier config /packages/prettier-config [Package] Escape HTML /packages/escape-html [Package] Interface /packages/interface [Package] Primitives /packages/primitives [Package] Icons /packages/icons [Tool] stylelint config /packages/stylelint-config [Package] Keyboard Shortcuts /packages/keyboard-shortcuts [Package] Edit Site /packages/edit-site [Package] Base styles /packages/base-styles [Tool] PostCSS Plugins Preset /packages/postcss-plugins-preset [Package] Warning /packages/warning [Package] React i18n /packages/react-i18n [Tool] Readable JS Assets Webpack Plugin /packages/readable-js-assets-webpack-plugin [Package] Style Engine /packages/style-engine [Package] Preferences /packages/preferences [Package] Media Utils /packages/media-utils labels Oct 28, 2026
gutenberg_get_ui_component() returns Gutenberg_UI_Safe_HTML again, so another component's output can be passed as content and is inserted as HTML, while plain strings are escaped. Closures and sanitized() HTML are accepted too.

Based on the review: trusted() is gone, so the object only comes from a component's output or from sanitized(), its constructor is private, and it can't be unserialized. __toString() stays so echo keeps working; the templating in wordpress-develop#5949 could replace this object later.
@juanfra

juanfra commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

I've rebuilt this on top of #85759 and changed the base branch. Added an update at the top of the description with what changed based on all the feedback here, so that we don't lose any information.

Sorry for all the noise with labels. I pushed before changing the base, and the automation triggered.

…6-ui-components-php-card

# Conflicts:
#	packages/ui/bin/build-php.mjs
…6-ui-components-php-card

# Conflicts:
#	phpunit/experimental/ui-components-test.php
* @param string $html HTML rendered by a component.
* @return Gutenberg_UI_Safe_HTML Safe HTML.
*/
function gutenberg_ui_components_safe_html( $html ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps safe is conveying more than it should. what about just marking that it’s been sanitized?

function gutenberg_make_sanitized_html( $html ) { ... }

}
if ( $content instanceof Gutenberg_UI_Safe_HTML ) {
return (string) $content;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition is an example of why I suggested anonymous classes. we’ve exposed a safe primitive to the public, and I worry that this will encourage misuse of the class.

did you explore an anonymous class trapped inside a sanitizing class?
https://3v4l.org/aOOj7

it’s a bit cumbersome, but replaces these abstraction leaks with a more normative exchange with the wrapping class.

the condition here would be replaced with Gutenberg_Sanitized_HTML::render( $string_or_wrapped_value ), where it would unpack the types and keep them all in a single file. I don’t see any reason to ever call instance Private_Secured_Wrapper

class Outer {
    private static $inner = null;
    
    private function __construct() {
        
    }
    
    private static function ensure() {
        if ( isset( self::$inner ) ) {
            return;
        }
        
        self::$inner = new class () {
            private $html = '';
        
            
            public static function wrap( $html ) {
                $self = new self();
                $self->html = $html;
                
                return $self;
            }
            
            public static function unwrap( $self ) {
                return $self->html;
            }
        };
    }
    
    public static function wrap( $html ) {
        self::ensure();
        
        return self::$inner::wrap( $html );
    }
    
    public static function unwrap( $self ) {
        return $self instanceof self::$inner
            ? self::$inner::unwrap( $self )
            : $self;
    }
}

$wrapped = Outer::wrap( '<div>just <script>a test</script> some HTML</div>' );
var_dump( $wrapped );
var_dump( Outer::unwrap( $wrapped ) );

// Can’t call this from outside `Outer` because of the anonymous class.
// var_dump( $wrapped->unwrap() );

// It’s still possible to call via a self-reference, but that’s awkward and will stand out.
var_dump( $wrapped::unwrap( $wrapped ) );

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants