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 6076179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:34:42+00:00 2026-05-23T10:34:42+00:00

According to the official documentation , there is a way to provide callbacks for

  • 0

According to the official documentation, there is a way to provide callbacks for custom YAML tags:

mixed yaml_parse ( string $input [, int $pos = 0 [, int &$ndocs [, array $callbacks ]]] )

callbacks
Content handlers for YAML nodes. Associative array of YAML tag => callback mappings.

However, there seems to be no other documentation on the subject, even in the extension source!

I created this script as a test:

<?php

$yaml =<<<YAML
---
prop: !custom val
YAML;

print_r(yaml_parse($yaml,0,$n,array(
  YAML_STR_TAG => function () {
    echo "YAML_STR_TAG\n";
    $args = func_get_args();
    print_r($args);
    return 'x';
  },
  '!custom' => function () {
    echo "!custom\n";
    $args = func_get_args();
    print_r($args);
    return 'y';
  }
)));

And I got this output:

$ php yaml.php
YAML_STR_TAG
Array
(
    [0] => prop
    [1] => tag:yaml.org,2002:str
    [2] => 1
)
!custom
Array
(
    [0] => val
    [1] => !custom
    [2] => 1
)
Array
(
    [x] => y
)

From that I can tell several things:

  • The key used in the callback lookup is either one of PHP-YAML’s predefined constants or the custom tag used in the YAML source, including the exclamation point
  • Each key and value in a map gets “tagged” and passed to the matching callback, probably because according to the YAML spec the key can be any valid type as well.
  • Three arguments are passed to the callback: the “subject” of the tag, the tag itself, and some number, probably corresponding to a YAML_*_SCALAR_STYLE constant.
  • The return value of callbacks replaces the tagged data structure

Can anyone confirm the expected behavior of this function?

  • 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-23T10:34:42+00:00Added an answer on May 23, 2026 at 10:34 am

    After much research and testing, I have found some answers.

    As found in the extension’s unit tests, each callback takes three arguments:

    • mixed $data – The tagged data, already parsed
    • string $tag – The tag name, expanded according to the offical YAML tag specs:
      • !custom expands to !custom if no tag prefix is defined
      • !custom expands to prefixcustom, where prefix is defined by the document meta-data %TAG ! prefix. Note there is not a leading exclamation mark
      • !!preset expands to the parser-defined internal type. See the YAML_*_TAG constants
      • !<verbatim-tag> expands to verbatim-tag`. Note there is not a leading exclamation mark.
    • integer $style – The scalar style used. See the YAML_*_SCALAR_STYLE constants

    The callback should return a mixed value for the parser to emit.

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

Sidebar

Related Questions

Here's the information according to the official documentation : There are four different pairs
Is there any way (official according to UML 2.0) to have sequence diagrams or
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to
According to the official documentation , os.path is a module. Thus, what is the
According to the official Python documentation for the weakref module the primary use for
According to the official documentation , the KeyDown event on a Windows Forms control
The official documentation states the following: . But I have noticed that there are
According to PHP's official documentation the imagepng() function has the following signature: bool imagepng
According to the official Firebird documentation , columns containing Unicode strings (what SQL Server
Ok guys I'm little stacked here. According to official documentation Google says that Once

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.