<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alkhatib Adam</title>
    <description>The latest articles on DEV Community by Alkhatib Adam (@alkhatibdev).</description>
    <link>https://dev.to/alkhatibdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1231007%2F4edf67db-e028-4efe-8c25-1050f5b59f94.jpeg</url>
      <title>DEV Community: Alkhatib Adam</title>
      <link>https://dev.to/alkhatibdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alkhatibdev"/>
    <language>en</language>
    <item>
      <title>Does Claude Code actually use our MCP server? I measured it</title>
      <dc:creator>Alkhatib Adam</dc:creator>
      <pubDate>Wed, 04 Nov 2026 07:18:17 +0000</pubDate>
      <link>https://dev.to/alkhatibdev/does-claude-code-actually-use-our-mcp-server-i-measured-it-2dm7</link>
      <guid>https://dev.to/alkhatibdev/does-claude-code-actually-use-our-mcp-server-i-measured-it-2dm7</guid>
      <description>&lt;p&gt;A search engine is useless if nobody asks it anything. DPOLens gives an AI coding assistant the text of privacy law, but that only matters if the AI assistant looks the law up while it writes code that touches personal data. So I measured whether Claude Code does, without being told to.&lt;/p&gt;

&lt;p&gt;It did, every time it should have, and before it changed a line of code. The surprise was what made it do so.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question behind everything else
&lt;/h2&gt;

&lt;p&gt;Last week I wrote about &lt;a href="https://dpolens.com/blog/reranker-made-search-worse" rel="noopener noreferrer"&gt;how well DPOLens's search finds the right clause&lt;/a&gt;. That number assumes somebody asks. If Claude Code writes the code that stores a customer's ID number without ever calling DPOLens, a perfect search changes nothing.&lt;/p&gt;

&lt;p&gt;An MCP server can't make an AI assistant call it. It can only describe its tools, and send a few sentences of instructions when the AI assistant connects. Whether those are enough is something you can only find out by watching.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;I built Larder, a small shop backend: accounts, orders, logging, an analytics call to Segment and a welcome email, plus a product catalogue and a front page that hold nothing about people.&lt;/p&gt;

&lt;p&gt;Then I wrote 30 tasks for it, the kind of thing a developer types into Claude Code on an ordinary day:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;12 coding tasks that touch personal data.&lt;/strong&gt; "Drivers have to check ID when they deliver a high-value order. Store the type and number of the ID they checked on the order." "Add the client IP and user agent to the request log line."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;15 coding tasks that don't.&lt;/strong&gt; "Add ?sort=price and ?sort=newest to the products list." "Add a dark theme to the front page that follows the system setting."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3 questions about the rules.&lt;/strong&gt; "If someone got hold of our users table, who would we have to tell, and how quickly?"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule I held myself to: no coding task says "privacy", "GDPR", "consent" or "compliant". A task that did would make any AI assistant reach for a privacy tool, and the number would mean nothing. Claude Code has to notice on its own that storing an ID number is the kind of change that has rules.&lt;/p&gt;

&lt;p&gt;Six of the fifteen that don't touch personal data are near misses, written to catch an AI assistant that searches at the first sight of a user. "Rename User.name to displayName in the schema and everywhere in the code" changes the column a name is kept in, but it doesn't change what is collected, kept or shared.&lt;/p&gt;

&lt;h2&gt;
  
  
  How each run worked
&lt;/h2&gt;

&lt;p&gt;Every run started in a new container: Claude Code at a pinned version, with an empty profile and DPOLens installed the way the README says to, from the plugin marketplace. Nothing else: no &lt;code&gt;CLAUDE.md&lt;/code&gt;, no memory, no other plugins. It worked in a fresh copy of Larder, connected to a DPOLens instance that held GDPR.&lt;/p&gt;

&lt;p&gt;A run counted as a search if Claude Code called &lt;code&gt;search_policies&lt;/code&gt; or &lt;code&gt;get_clause&lt;/code&gt;, the two tools that return the law's text. It counted as searching first if that call came before its first edit to a file. Each task ran three times, 90 runs in all, with Claude Code 2.1.288 and Claude Sonnet 5.5.&lt;/p&gt;

&lt;h2&gt;
  
  
  The results
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tasks&lt;/th&gt;
&lt;th&gt;Searched&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Personal data&lt;/td&gt;
&lt;td&gt;36 of 36&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No personal data&lt;/td&gt;
&lt;td&gt;3 of 45&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Questions&lt;/td&gt;
&lt;td&gt;9 of 9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every run of every task that touched personal data searched, and every one of them searched before its first edit. Not after writing the code and checking it, but before.&lt;/p&gt;

&lt;p&gt;Every task behaved the same way in all three of its runs. None searched sometimes and not other times.&lt;/p&gt;

&lt;p&gt;Thirty-six out of thirty-six doesn't mean it can never miss. Twelve tasks with no misses means that the share of tasks like these that would miss is probably below one in four. That's the honest bound, and it's a long way from "always".&lt;/p&gt;

&lt;h2&gt;
  
  
  The three searches it didn't need
&lt;/h2&gt;

&lt;p&gt;All three unneeded searches were the same task, once in each run: "Send a product_viewed event to Segment when a product page is opened, with the product slug."&lt;/p&gt;

&lt;p&gt;The event carries nothing about the person viewing the page, so I'd labelled it as needing no search. Claude Code asked DPOLens about "sending product page view analytics events to a third-party service such as Segment". That's a fair question, and the number counts it against DPOLens anyway, because that's what the label says.&lt;/p&gt;

&lt;h2&gt;
  
  
  The surprising part
&lt;/h2&gt;

&lt;p&gt;DPOLens's Claude Code plugin brings three things: the MCP server, two commands, and a skill whose description tells Claude Code when to use DPOLens. It would be easy to credit the skill with these results.&lt;/p&gt;

&lt;p&gt;So I ran all 90 again with only the MCP server added, and no plugin.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tasks&lt;/th&gt;
&lt;th&gt;Plugin&lt;/th&gt;
&lt;th&gt;Server&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Personal data&lt;/td&gt;
&lt;td&gt;36 of 36&lt;/td&gt;
&lt;td&gt;36 of 36&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No personal data&lt;/td&gt;
&lt;td&gt;3 of 45&lt;/td&gt;
&lt;td&gt;0 of 45&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Questions&lt;/td&gt;
&lt;td&gt;9 of 9&lt;/td&gt;
&lt;td&gt;9 of 9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Without the skill, it did just as well, and slightly better: the Segment task stopped searching.&lt;/p&gt;

&lt;p&gt;The difference comes down to a few words. The skill's description said to use DPOLens "when sending data to another service". The product view sends data to another service, just not data about anyone. The server's own instructions say this instead:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Search DPOLens before writing or changing code that collects, stores, logs, shares or deletes personal data, and before answering a question about what a policy or the law requires.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;"Personal data", not "data". One word was the difference between three unneeded searches and none.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The instructions an MCP server sends when it connects do most of the work.&lt;/strong&gt; They're a few sentences, and easy to leave empty. Write them like the most important prompt you own, because they are.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Say exactly when to use the tool.&lt;/strong&gt; The sentence names five actions (collects, stores, logs, shares, deletes) and one kind of data, and it lists what counts as personal data. Vague guidance triggers on vague matches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test the near misses.&lt;/strong&gt; A tool that fires on every mention of a user is as useless as one that never fires. The renamed column and the session length told me as much as the ID numbers did.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure before you add more guidance.&lt;/strong&gt; More instructions feel safer. The measurement showed that the server's sentence was already enough, and that the extra words made it slightly worse.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What this doesn't show
&lt;/h2&gt;

&lt;p&gt;Only Claude Code was measured, on one model, in October. Codex, Cursor and GitHub Copilot in VS Code read the same guidance, but I haven't measured how often they act on it. The tasks are short and plainly worded, in a small app; in a large codebase the code that handles people's data is harder to spot. And a run stops at its first search, so this measures whether Claude Code looks the law up, not what it does with what it finds.&lt;/p&gt;

&lt;p&gt;The 30 tasks, the app, the scoring and the commands to run it yourself are in &lt;a href="https://github.com/alkhatibdev/dpolens/blob/main/evals/trigger-test.md" rel="noopener noreferrer"&gt;Does an AI assistant actually use it&lt;/a&gt;. DPOLens is open source, under the Apache License 2.0.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First published on &lt;a href="https://dpolens.com/blog/does-claude-code-use-it" rel="noopener noreferrer"&gt;dpolens.com&lt;/a&gt;. DPOLens is an open-source MCP server that gives AI assistants privacy law and an organisation's own policies, clause by clause: &lt;a href="https://github.com/alkhatibdev/dpolens" rel="noopener noreferrer"&gt;github.com/alkhatibdev/dpolens&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>claude</category>
      <category>opensource</category>
    </item>
    <item>
      <title>A reranker made my legal search worse</title>
      <dc:creator>Alkhatib Adam</dc:creator>
      <pubDate>Tue, 27 Oct 2026 11:26:15 +0000</pubDate>
      <link>https://dev.to/alkhatibdev/a-reranker-made-my-legal-search-worse-1lnn</link>
      <guid>https://dev.to/alkhatibdev/a-reranker-made-my-legal-search-worse-1lnn</guid>
      <description>&lt;p&gt;I expected a reranker to make DPOLens's search better. It made it worse every time I measured it, and the more results it reordered, the worse it got. This post is how I measured that, the bugs I looked for and didn't find, and why DPOLens ships without one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Developers and the law use different words
&lt;/h2&gt;

&lt;p&gt;DPOLens is an MCP server that gives AI assistants the text of privacy law, so an answer can quote the clause it relies on. Its search has to find that clause from a question written the way a developer writes it.&lt;/p&gt;

&lt;p&gt;That's harder than it sounds. A developer asks "do we have to delete a user's data when they ask?". GDPR Article 17(1)(b) never says "delete". It says the data subject "withdraws consent on which the processing is based". The words a developer types and the words that answer them often have nothing in common.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I measured search
&lt;/h2&gt;

&lt;p&gt;I wrote 50 questions about GDPR, phrased the way developers ask them. The answer to each one, the clause that counts as correct, doesn't come from me: it comes from guidance published by data protection regulators, and a script fetches each source and reports whether it names the clause.&lt;/p&gt;

&lt;p&gt;I split the questions in two:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;20 practice questions, which I could look at as often as I liked while improving search&lt;/li&gt;
&lt;li&gt;30 held-out questions, used only for the final score&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The score is recall@5: how often the right clause is among the first five results. Thirty questions is a small set, so every score comes with a 95% confidence interval. For 0.77, the interval runs from 0.60 to 0.90. That width matters later.&lt;/p&gt;

&lt;p&gt;Every number in this post was measured on the 30 held-out questions on 26 September 2026.&lt;/p&gt;

&lt;h2&gt;
  
  
  What worked: two searches together
&lt;/h2&gt;

&lt;p&gt;DPOLens runs two kinds of search over the same clauses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keyword search&lt;/strong&gt; (BM25) finds clauses that share words with the question. It's what you need when you type "Article 17" or a term the law defines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning search&lt;/strong&gt; uses a small embedding model, multilingual-e5-small, which runs locally on the CPU. It turns the question and each clause into numbers and finds the clauses whose meaning is closest, even when no word matches.&lt;/p&gt;

&lt;p&gt;Then the two lists are combined into one.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Search&lt;/th&gt;
&lt;th&gt;recall@5&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Keyword only&lt;/td&gt;
&lt;td&gt;0.30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Meaning only&lt;/td&gt;
&lt;td&gt;0.43&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Meaning, no recitals&lt;/td&gt;
&lt;td&gt;0.60&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Both, combined&lt;/td&gt;
&lt;td&gt;0.77&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The third row needs a sentence. GDPR's recitals explain the law in long, plain sentences, but they don't oblige anyone to do anything. Because they're written in plain language, they matched conversational questions better than the short article that actually creates the duty. Leaving them out of search by default lifted meaning search alone by 17 points. They're still stored, and you can still ask for them.&lt;/p&gt;

&lt;p&gt;Combining both searches took it to 0.77. Each one finds clauses the other misses.&lt;/p&gt;

&lt;h2&gt;
  
  
  The standard next step: a reranker
&lt;/h2&gt;

&lt;p&gt;The usual advice for the search half of a RAG pipeline is to add a reranker on top. A reranker is a second model, a cross-encoder, that reads the question and one clause together and gives the pair a single score. Meaning search turns the question and the clause into numbers separately, so a model that reads them side by side should judge better. It's also much slower, so it only reorders the top of the list.&lt;/p&gt;

&lt;p&gt;DPOLens searches Arabic as well as English, so the reranker had to be multilingual. I tested jina-reranker-v2-base-multilingual, reordering the top 10, the top 25 and the top 50 results, and timed each question.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reranked&lt;/th&gt;
&lt;th&gt;recall@5&lt;/th&gt;
&lt;th&gt;Seconds&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;0.77&lt;/td&gt;
&lt;td&gt;0.11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top 10&lt;/td&gt;
&lt;td&gt;0.57&lt;/td&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top 25&lt;/td&gt;
&lt;td&gt;0.47&lt;/td&gt;
&lt;td&gt;1.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top 50&lt;/td&gt;
&lt;td&gt;0.43&lt;/td&gt;
&lt;td&gt;4.4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Worse at every depth, and steadily worse the deeper it went, at up to 40 times the time per question. The larger embedding model, e5-base, told the same story: 0.80 without the reranker, then 0.67, 0.57 and 0.53.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking for my own bug
&lt;/h2&gt;

&lt;p&gt;When a standard technique makes things worse, the likeliest explanation is that I broke something. So before believing the numbers, I checked the three places a reranker is usually wired up wrong:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The output.&lt;/strong&gt; The model returns a score for each pair, and reading the wrong position in its output gives scores that mean nothing. I was reading the right one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The direction.&lt;/strong&gt; If a higher score meant less relevant, sorting the usual way would put the worst results first. It doesn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The input.&lt;/strong&gt; A cross-encoder expects the question and the clause joined in a set format. The encoded input had the expected &lt;code&gt;query &amp;lt;/s&amp;gt;&amp;lt;/s&amp;gt; passage&lt;/code&gt; form.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All three were right. The reranker was doing what it was built to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was actually happening
&lt;/h2&gt;

&lt;p&gt;The answer was in the scores. For a question about reporting a data breach, the reranker scored the clause that answers it at -2.11. It scored boilerplate about the date the regulation enters into force at -2.20.&lt;/p&gt;

&lt;p&gt;Those numbers are almost the same. The model could barely tell a direct answer from unrelated legal text. Combining the two searches had already put the right clause near the top, and reordering by scores that close shuffled a ranking that was already good. The more results it reordered, the more of that ranking it lost.&lt;/p&gt;

&lt;p&gt;My guess is that law is a hard case for a general-purpose reranker: every clause is formal and long and uses the same vocabulary, so sounding like law tells it nothing. I haven't proven that. What I measured is that this model, on this law, made the results worse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I didn't just try another one
&lt;/h2&gt;

&lt;p&gt;I'd have liked to. The other multilingual candidate I'd picked, bge-reranker-v2-m3, has no ONNX build, and exporting one needs PyTorch, which DPOLens leaves out to keep its image small. The other well-known rerankers are English only, and DPOLens has to answer in Arabic.&lt;/p&gt;

&lt;p&gt;So the reranker code stays in the repository, unused. When a better multilingual cross-encoder comes out, the same experiment can run again on the same questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap I nearly fell into
&lt;/h2&gt;

&lt;p&gt;There's a second lesson here, and it's about the 20 practice questions.&lt;/p&gt;

&lt;p&gt;On those 20, combining both searches scored lower than meaning search alone: 0.45 against 0.60. While I was building, that read as clear evidence that combining them was hurting. On the 30 held-out questions it was the other way round: 0.77 against 0.60.&lt;/p&gt;

&lt;p&gt;Same code, same law, different questions. Two small sets are not equally hard, so you can compare settings within one set, never across two. Had I trusted the practice set, I would have dropped the combined search and lost 17 points.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Measure the standard pattern before you ship it.&lt;/strong&gt; A reranker is a sensible default for many search pipelines. On this one it cost recall and 40 times the time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look for your own bug first, then believe the numbers.&lt;/strong&gt; Ruling out the three usual mistakes is what made me trust the result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the uncertainty next to the score.&lt;/strong&gt; 0.77, with an interval from 0.60 to 0.90, is honest. A bare 0.77 claims more than thirty questions can support.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the experiment.&lt;/strong&gt; Leaving the code in means the question can be asked again when the models get better.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every configuration, the questions and how to reproduce the scores are in &lt;a href="https://github.com/alkhatibdev/dpolens/blob/main/evals/retrieval.md" rel="noopener noreferrer"&gt;How retrieval works, and how well&lt;/a&gt;, and the reranker is in &lt;a href="https://github.com/alkhatibdev/dpolens/blob/main/packages/dpolens/src/dpolens/engine/search/rerank.py" rel="noopener noreferrer"&gt;rerank.py&lt;/a&gt;. DPOLens is open source, under the Apache License 2.0.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First published on &lt;a href="https://dpolens.com/blog/reranker-made-search-worse" rel="noopener noreferrer"&gt;dpolens.com&lt;/a&gt;. DPOLens is an open-source MCP server that gives AI assistants privacy law and an organisation's own policies, clause by clause: &lt;a href="https://github.com/alkhatibdev/dpolens" rel="noopener noreferrer"&gt;github.com/alkhatibdev/dpolens&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rag</category>
      <category>search</category>
      <category>machinelearning</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Evolution of Type Hinting in PHP</title>
      <dc:creator>Alkhatib Adam</dc:creator>
      <pubDate>Wed, 20 Dec 2023 15:59:56 +0000</pubDate>
      <link>https://dev.to/alkhatibdev/evolution-of-type-hinting-in-php-9gm</link>
      <guid>https://dev.to/alkhatibdev/evolution-of-type-hinting-in-php-9gm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;PHP, being a dynamically typed language, traditionally allowed flexibility in variable types, providing both advantages and challenges in code maintenance and robustness. However, with the introduction of PHP 7, the language underwent significant improvements, and one crucial enhancement was the introduction of type hinting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evolution of Type Hinting in PHP:
&lt;/h2&gt;

&lt;p&gt;PHP 5: Before PHP 7, type hinting was primarily limited to objects and arrays in function and method signatures. Developers had to rely on runtime checks to ensure variable types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 5 style type hinting for objects&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;processUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PHP 7: The release of PHP 7 marked a paradigm shift by introducing scalar type declarations. Developers gained the ability to specify the expected data types for function parameters and return values, improving code predictability and catching potential errors at an earlier stage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 7 scalar type hinting for parameters and return values&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;addNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scalar Type Declarations:
&lt;/h2&gt;

&lt;p&gt;PHP 7 introduced scalar type declarations for int, float, string, and bool types. This meant that functions could explicitly specify the types they expected for primitive data types, enhancing code clarity and reducing the likelihood of unexpected data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Return Type Declarations:
&lt;/h2&gt;

&lt;p&gt;Complementing parameter type hints, PHP 7 also introduced return type declarations. Functions and methods could now declare the expected type of the value they would return, providing developers and IDEs with valuable information about the function's behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 7 return type declaration&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Nullable Types:
&lt;/h2&gt;

&lt;p&gt;PHP 7.1 introduced the ability to specify that a parameter or return type could be nullable by appending a ? before the type. This addition acknowledged the common scenario where a function could accept or return null.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 7.1 nullable type&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;processString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Union Types:
&lt;/h2&gt;

&lt;p&gt;PHP 8.0 expanded type hinting further with the introduction of union types. Developers could specify that a parameter or return type could be one of several types, providing increased flexibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 8.0 union type&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;processValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;float&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Named Arguments:
&lt;/h2&gt;

&lt;p&gt;PHP 8.0 also introduced named arguments, allowing developers to pass arguments to a function by specifying the parameter name. This feature enhances code readability and makes it easier to work with functions that have a large number of parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// PHP 8.0 named arguments&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nv"&gt;$urgent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'john@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Hello, John!'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;urgent&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pros and Cons of Type Hinting in PHP
&lt;/h2&gt;

&lt;p&gt;While type hinting in PHP offers numerous benefits in terms of code quality and maintainability, it's essential to consider the specific needs of a project and the development team's preferences. Striking the right balance between strictness and flexibility is key to harnessing the advantages of type hinting effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Code Readability:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type hinting enhances code readability by providing clear information about the expected data types for function parameters and return values. This makes it easier for developers to understand how to use functions correctly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Error Prevention:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type hinting helps catch potential errors at an earlier stage of development. If a function is called with incorrect data types, PHP will issue a warning or error, preventing runtime issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Documentation and IDE Support:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type hints serve as a form of self-documentation, making it explicit what types of data a function is designed to work with. This documentation is also utilized by Integrated Development Environments (IDEs) to offer better code suggestions and autocompletions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhanced Code Predictability:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By specifying the expected types of parameters and return values, type hinting improves code predictability. Developers can better anticipate the behavior of functions and methods, reducing the chances of unexpected outcomes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easier Maintenance:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Codebases with type hints tend to be easier to maintain. When developers revisit or collaborate on code, the explicit type of information helps them understand the intended usage and purpose of each function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool Support:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many modern development tools and static analysis tools leverage type hints to provide better insights into code quality and potential issues. This support enhances the overall development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cons:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Strictness and Flexibility Trade-off:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While type hinting enforces strict data typing, it may introduce inflexibility in scenarios where loose typing could be beneficial. Some developers prefer the flexibility of dynamically typed languages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backward Compatibility:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Introducing type hints to an existing codebase can be challenging due to backward compatibility concerns. Existing code might not adhere to the new type constraints, requiring significant refactoring.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learning Curve:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Developers new to type hinting or those transitioning from dynamically typed languages may experience a learning curve. Understanding how to correctly use type hints and when to apply them effectively requires familiarity and practice.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runtime Performance Overhead:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type hints can introduce a slight runtime performance overhead, especially in scenarios where type checking is involved. While the impact is often minimal, it's a consideration for performance-critical applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increased Boilerplate Code:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In some cases, type hinting can lead to increased boilerplate code, especially when dealing with complex data structures. This may slightly reduce code brevity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not Applicable Everywhere:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are situations where type hinting might not be applicable or suitable. For example, when working with external libraries that do not use type hints, enforcing strict typing throughout the codebase may not be feasible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;PHP type hinting has undergone continuous refinement and expansion, providing developers with powerful tools to enhance code quality, maintainability, and predictability. By leveraging type hinting features introduced in PHP 7 and subsequent versions, developers can create more robust and error-resistant code, leading to improved software reliability and a better development experience.&lt;/p&gt;

</description>
      <category>php</category>
      <category>typehinting</category>
      <category>programming</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
