{"id":1475,"date":"2024-02-24T14:41:46","date_gmt":"2024-02-24T13:41:46","guid":{"rendered":"https:\/\/bitsolto.com\/bitacora\/?p=1475"},"modified":"2024-02-24T18:59:33","modified_gmt":"2024-02-24T17:59:33","slug":"depurar-php-en-vscode","status":"publish","type":"post","link":"https:\/\/bitsolto.com\/bitacora\/webdev\/depurar-php-en-vscode\/","title":{"rendered":"Depurar PHP en VSCode"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1475\" class=\"elementor elementor-1475\">\n\t\t\t\t<div class=\"elementor-element elementor-element-3940d835 e-flex e-con-boxed e-con e-parent\" data-id=\"3940d835\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1957c3fd elementor-widget elementor-widget-text-editor\" data-id=\"1957c3fd\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p><\/p>\n<h3>Depurar PHP en VSCode<\/h3>\n<p><\/p>\n<p><\/p>\n<p>VSCode disp\u00f3n para PHP, coma para outras linguaxes, de algunhas funci\u00f3ns como resaltado de sintaxe, coincidencia de corchetes, auto completado de c\u00f3digo e fragmentos listos para usar. Ademais se lle poden agregar a\u00ednda m\u00e1is funci\u00f3ns a trav\u00e9s de extensi\u00f3ns.<\/p>\n<p><\/p>\n<p><\/p>\n<h3>Linting (espeluxando)<\/h3>\n<p><\/p>\n<p><\/p>\n<p>VS Code utiliza o <em>linter<\/em> oficial de PHP (&lt;code&gt;php -l&lt;\/code&gt;) para o diagn\u00f3stico da linguaxe PHP.<\/p>\n<p><\/p>\n<p><\/p>\n<p>Se usas Xampp, Laragon,&#8230; ou calquera outra suite *AMP, aseg\u00farate de ter unha instalaci\u00f3n completa de PHP.<\/p>\n<p><\/p>\n<p><\/p>\n<p>Hai tres configuraci\u00f3ns para controlar o <em>linter<\/em> PHP:<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; &#8220;php.validate.enable&#8220;: controla si se habilita o linting de PHP. Habilitado de forma predeterminada.<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; &#8220;php.validate.executablePath&#8220;: apunta ao executable PHP no disco. Configura isto <strong>se o executable PHP non est\u00e1 na ruta do sistema<\/strong>.<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; &#8220;php.validate.run&#8220;: controla se a validaci\u00f3n se activa ao gardar &#8211; `&#8221;onSave&#8221;` &#8211; ou ao escribir &#8211; `&#8221;onType&#8221;` -. O valor predeterminado \u00e9 `&#8221;onSave&#8221;`.<\/p>\n<p><\/p>\n<p><\/p>\n<p>Para cambiar a configuraci\u00f3n de PHP, abre a <strong>Configuraci\u00f3n de usuario<\/strong>&nbsp;ou de <strong>espazo de traballo<\/strong>&nbsp;( `Ctrl + ,` ) &#8211; escribe &#8216;php&#8217; para filtrar a lista de configuraci\u00f3ns dispo\u00f1ibles.<\/p>\n<p><\/p>\n<p><\/p>\n<h3>Extensi\u00f3ns<\/h3>\n<p><\/p>\n<p><\/p>\n<p>Existen moitas extensi\u00f3ns dispo\u00f1ibles para PHP &#8211; unhas 830 alo menos a dia de hoxe.<\/p>\n<p><\/p>\n<p><\/p>\n<p>A \u00faneca que poder\u00eda recomendar para un uso xeral \u00e9 <strong>**[<\/strong><strong>PHP TOOLS<\/strong><strong>](<\/strong>https:\/\/marketplace.visualstudio.com\/items?itemName=DEVSENSE.phptools-vscode<strong>)**<\/strong>.<\/p>\n<p><\/p>\n<p><\/p>\n<h3>## Depuraci\u00f3n<\/h3>\n<p><\/p>\n<p><\/p>\n<p>VSCode admite a depuraci\u00f3n de PHP con XDebug a trav\u00e9s da extensi\u00f3n &#8216;[PHP Debug](https:\/\/marketplace.visualstudio.com\/items?itemName=xdebug.php-debug)&#8217;.<\/p>\n<p><\/p>\n<p><\/p>\n<p>:eye: Esta extensi\u00f3n xa ven integrada en &#8216;PHP Tool&#8217;.<\/p>\n<p><\/p>\n<p><\/p>\n<p>Comproba que ademais tes instalada e habilitada a extensi\u00f3n XDebug na configuraci\u00f3n do teu servidor de proba. Ver `php.ini`.<\/p>\n<p><\/p>\n<p><\/p>\n<h3>Crear perfil de depuraci\u00f3n<\/h3>\n<p><\/p>\n<p><\/p>\n<h4>i<\/h4>\n<p><\/p>\n<p><\/p>\n<p>&#8211; Abrir o teu arquivo ou proxecto PHP<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; Premer F5<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; Seleccionar: &#8216;Profile current script&#8217;<\/p>\n<p><\/p>\n<p><\/p>\n<h4>ii<\/h4>\n<p><\/p>\n<p><\/p>\n<p>&#8211; Executar o servidor local<\/p>\n<p><\/p>\n<p><\/p>\n<p>&#8211; Executar e depurar<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &#8211; Crear `launch.json` (para Xdebug)<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &#8211; Editar `launch.json`<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp;&#8220;`json<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp;&#8230;<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp;&#8220;configurations&#8221;: [<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; {<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; <em>+<\/em> &nbsp; &#8220;name&#8221;: &#8220;Launch built-in server and profile&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;type&#8221;: &#8220;php&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;request&#8221;: &#8220;launch&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;runtimeArgs&#8221;: [<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;-S&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;localhost:8000&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;-t&#8221;,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; <em>+<\/em> &nbsp; &nbsp; &nbsp; &#8220;.\/public&#8221; &nbsp;\/\/ apuntar ao index.php raiz do proxecto<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; <em>+<\/em> &nbsp; &#8220;profile&#8221;: true,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; <em>+<\/em> &nbsp; &#8220;openProfile&#8221;: true,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;port&#8221;: 9003,<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;serverReadyAction&#8221;: {<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;action&#8221;: &#8220;openExternally&#8221;<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; },<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; <em>&#8230;<\/em><\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; ]<\/p>\n<p><\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp;&#8220;`<\/p>\n<p><\/p>\n<p><\/p>\n<p>Xa tes un perfil de depuraci\u00f3n para o teu proxecto. Executa o servidor local cando precises verificar o teu c\u00f3digo, este perfil gardado en `launch.json` aplicar\u00e1 a s\u00faa configuraci\u00f3n a dito proceso.<\/p>\n<p><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Depurar PHP en VSCode VSCode disp\u00f3n para PHP, coma para outras linguaxes, de algunhas funci\u00f3ns como resaltado de sintaxe, coincidencia de corchetes, auto completado de c\u00f3digo e fragmentos listos para usar. Ademais se lle poden agregar a\u00ednda m\u00e1is funci\u00f3ns a trav\u00e9s de extensi\u00f3ns. Linting (espeluxando) VS Code utiliza o linter oficial de PHP (&lt;code&gt;php -l&lt;\/code&gt;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1036,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","omw_enable_modal_window":"enable","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[26],"tags":[65,56],"class_list":["post-1475","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webdev","tag-php","tag-vscode","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/posts\/1475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/comments?post=1475"}],"version-history":[{"count":10,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/posts\/1475\/revisions"}],"predecessor-version":[{"id":1544,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/posts\/1475\/revisions\/1544"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/media\/1036"}],"wp:attachment":[{"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/media?parent=1475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/categories?post=1475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitsolto.com\/bitacora\/wp-json\/wp\/v2\/tags?post=1475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}